app: let the settings hide limit windows and give the app an icon #18
@@ -120,6 +120,8 @@ a screenshot of each changed view: compiling is not working.
|
|||||||
|
|
||||||
## Tools
|
## Tools
|
||||||
|
|
||||||
|
- `tools/icon/make_icon.py`: renders the shared app icon with development-only Pillow 11.3.0.
|
||||||
|
Run `python -B tools/icon/make_icon.py`; test with `python -B tools/icon/test_make_icon.py`.
|
||||||
- `tools/docs/check_docs.py`: the documentation check; its tests are
|
- `tools/docs/check_docs.py`: the documentation check; its tests are
|
||||||
`python -B tools/docs/test_check_docs.py`.
|
`python -B tools/docs/test_check_docs.py`.
|
||||||
- `tools/gitea.sh`: calls the Gitea API with the stored git credential or `GITEA_TOKEN`.
|
- `tools/gitea.sh`: calls the Gitea API with the stored git credential or `GITEA_TOKEN`.
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Platform;
|
||||||
|
|
||||||
|
namespace FinalToken.App;
|
||||||
|
|
||||||
|
public static class AppIcon
|
||||||
|
{
|
||||||
|
// Keep the ICO's multiple sizes on Windows; X11 uses the same artwork as a PNG (D8).
|
||||||
|
public static WindowIcon Load()
|
||||||
|
{
|
||||||
|
var extension = OperatingSystem.IsWindows() ? "ico" : "png";
|
||||||
|
using var stream = AssetLoader.Open(new Uri($"avares://FinalToken/Assets/FinalToken.{extension}"));
|
||||||
|
return new WindowIcon(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
@@ -1,9 +1,6 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.Media;
|
|
||||||
using Avalonia.Media.Imaging;
|
|
||||||
using Avalonia.Themes.Fluent;
|
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using FinalToken.Core;
|
using FinalToken.Core;
|
||||||
using FinalToken.Core.StreamDeck;
|
using FinalToken.Core.StreamDeck;
|
||||||
@@ -75,11 +72,7 @@ public sealed class DesktopApp : Application
|
|||||||
var menu = new NativeMenu();
|
var menu = new NativeMenu();
|
||||||
foreach (var (label, action) in new (string, Action)[] { ("Open", OpenPanel), ("Refresh now", () => Run(Refresh)), ("Settings", OpenSettings), ("Quit", () => Run(Quit)) })
|
foreach (var (label, action) in new (string, Action)[] { ("Open", OpenPanel), ("Refresh now", () => Run(Refresh)), ("Settings", OpenSettings), ("Quit", () => Run(Quit)) })
|
||||||
{ var item = new NativeMenuItem(label); item.Click += (_, _) => action(); menu.Items.Add(item); }
|
{ var item = new NativeMenuItem(label); item.Click += (_, _) => action(); menu.Items.Add(item); }
|
||||||
using var bitmap = new RenderTargetBitmap(new PixelSize(32, 32));
|
tray = new TrayIcon { Icon = AppIcon.Load(), ToolTipText = "FinalToken", Menu = menu, IsVisible = true };
|
||||||
using (var context = bitmap.CreateDrawingContext())
|
|
||||||
{ context.DrawRectangle(Brush.Parse("#3878D4"), null, new Rect(0, 0, 32, 32), 7, 7); context.DrawLine(new Pen(Brushes.White, 4), new(9, 9), new(23, 9)); context.DrawLine(new Pen(Brushes.White, 4), new(16, 9), new(16, 25)); }
|
|
||||||
using var stream = new MemoryStream(); bitmap.Save(stream, PngBitmapEncoderOptions.Default); stream.Position = 0;
|
|
||||||
tray = new TrayIcon { Icon = new WindowIcon(stream), ToolTipText = "FinalToken", Menu = menu, IsVisible = true };
|
|
||||||
tray.Clicked += (_, _) => OpenPanel();
|
tray.Clicked += (_, _) => OpenPanel();
|
||||||
TrayIcon.SetIcons(this, [tray]);
|
TrayIcon.SetIcons(this, [tray]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,10 @@
|
|||||||
<PublishAot>true</PublishAot>
|
<PublishAot>true</PublishAot>
|
||||||
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
<ApplicationIcon>Assets/FinalToken.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup><ProjectReference Include="../FinalToken.Core/FinalToken.Core.csproj" /></ItemGroup>
|
<ItemGroup><ProjectReference Include="../FinalToken.Core/FinalToken.Core.csproj" /></ItemGroup>
|
||||||
|
<ItemGroup><AvaloniaResource Include="Assets/*" /></ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Avalonia.Desktop" />
|
<PackageReference Include="Avalonia.Desktop" />
|
||||||
<PackageReference Include="Avalonia.Themes.Fluent" />
|
<PackageReference Include="Avalonia.Themes.Fluent" />
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public sealed class PanelWindow : Window
|
|||||||
{
|
{
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.clock = clock ?? TimeProvider.System;
|
this.clock = clock ?? TimeProvider.System;
|
||||||
|
Icon = AppIcon.Load();
|
||||||
Title = $"FinalToken {typeof(Program).Assembly.GetName().Version?.ToString(3)}";
|
Title = $"FinalToken {typeof(Program).Assembly.GetName().Version?.ToString(3)}";
|
||||||
Width = 1280; Height = 900; MinWidth = 960; MinHeight = 500; Ui.Theme(this);
|
Width = 1280; Height = 900; MinWidth = 960; MinHeight = 500; Ui.Theme(this);
|
||||||
var brand = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 8, VerticalAlignment = VerticalAlignment.Center };
|
var brand = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 8, VerticalAlignment = VerticalAlignment.Center };
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ public sealed class SettingsWindow : Window
|
|||||||
{
|
{
|
||||||
public SettingsWindow(Settings initial, PluginInstallStatus status, Func<Settings, Task> save, Action? quit = null, Action<string>? openFolder = null)
|
public SettingsWindow(Settings initial, PluginInstallStatus status, Func<Settings, Task> save, Action? quit = null, Action<string>? openFolder = null)
|
||||||
{
|
{
|
||||||
|
Icon = AppIcon.Load();
|
||||||
Title = "FinalToken settings"; Width = 760; Height = 900; MinWidth = 600; MinHeight = 500; Ui.Theme(this);
|
Title = "FinalToken settings"; Width = 760; Height = 900; MinWidth = 600; MinHeight = 500; Ui.Theme(this);
|
||||||
var body = new StackPanel { Spacing = 16, Margin = new Thickness(24) };
|
var body = new StackPanel { Spacing = 16, Margin = new Thickness(24) };
|
||||||
body.Children.Add(Ui.Text("Settings", 24));
|
body.Children.Add(Ui.Text("Settings", 24));
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""D8: render the shared usage gauge. Requires development-only Pillow 11.3.0."""
|
||||||
|
import argparse
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from PIL import Image, ImageDraw
|
||||||
|
|
||||||
|
SIZES = (16, 20, 24, 32, 40, 48, 64, 128, 256)
|
||||||
|
ASSETS = Path(__file__).resolve().parents[2] / 'src' / 'FinalToken.App' / 'Assets'
|
||||||
|
|
||||||
|
|
||||||
|
def render(size):
|
||||||
|
scale = size * 8
|
||||||
|
image = Image.new('RGBA', (scale, scale))
|
||||||
|
draw = ImageDraw.Draw(image)
|
||||||
|
|
||||||
|
def box(a, b, c, d):
|
||||||
|
return tuple(round(n * scale) for n in (a, b, c, d))
|
||||||
|
|
||||||
|
draw.rounded_rectangle(box(.025, .025, .975, .975), radius=round(.20 * scale),
|
||||||
|
fill='#1a1a19', outline='#52514e', width=round(.025 * scale))
|
||||||
|
gauge = box(.17, .17, .83, .83)
|
||||||
|
width = round(.115 * scale)
|
||||||
|
draw.arc(gauge, 135, 405, fill='#383835', width=width)
|
||||||
|
draw.arc(gauge, 135, 265, fill='#d95926', width=width)
|
||||||
|
draw.arc(gauge, 267, 353, fill='#3987e5', width=width)
|
||||||
|
# One chunky pointer survives the 16 px downsample; there are no small-size hairlines.
|
||||||
|
draw.line(box(.50, .53, .64, .37), fill='#f0efec', width=round(.075 * scale))
|
||||||
|
draw.ellipse(box(.445, .475, .555, .585), fill='#f0efec')
|
||||||
|
return image.resize((size, size), Image.Resampling.LANCZOS)
|
||||||
|
|
||||||
|
|
||||||
|
def write_assets(output):
|
||||||
|
output.mkdir(parents=True, exist_ok=True)
|
||||||
|
images = [render(size) for size in SIZES]
|
||||||
|
images[-1].save(output / 'FinalToken.ico', sizes=[(s, s) for s in SIZES], append_images=images[:-1])
|
||||||
|
images[-1].save(output / 'FinalToken.png')
|
||||||
|
|
||||||
|
|
||||||
|
def contact_sheet(path):
|
||||||
|
sizes = (16, 24, 32, 48, 256)
|
||||||
|
sheet = Image.new('RGB', (512, 640))
|
||||||
|
draw = ImageDraw.Draw(sheet)
|
||||||
|
for column, background in enumerate(('#f9f9f7', '#0d0d0d')):
|
||||||
|
left = column * 256
|
||||||
|
draw.rectangle((left, 0, left + 255, 639), fill=background)
|
||||||
|
y = 24
|
||||||
|
for size in sizes:
|
||||||
|
icon = render(size)
|
||||||
|
sheet.paste(icon, (left + (256 - size) // 2, y), icon)
|
||||||
|
y += size + 32
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
sheet.save(path)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument('--out', type=Path, default=ASSETS)
|
||||||
|
parser.add_argument('--contact-sheet', type=Path)
|
||||||
|
args = parser.parse_args()
|
||||||
|
write_assets(args.out)
|
||||||
|
if args.contact_sheet:
|
||||||
|
contact_sheet(args.contact_sheet)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Check all ICO frames and reproducible committed icon assets."""
|
||||||
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
from make_icon import ASSETS, SIZES, render
|
||||||
|
|
||||||
|
|
||||||
|
class IconTests(unittest.TestCase):
|
||||||
|
def test_ico_contains_every_size_and_its_rendered_pixels(self):
|
||||||
|
with Image.open(ASSETS / 'FinalToken.ico') as icon:
|
||||||
|
self.assertEqual({(s, s) for s in SIZES}, icon.ico.sizes())
|
||||||
|
for size in SIZES:
|
||||||
|
frame = icon.ico.getimage((size, size))
|
||||||
|
self.assertEqual(render(size).tobytes(), frame.tobytes())
|
||||||
|
|
||||||
|
def test_fresh_run_reproduces_committed_files_byte_for_byte(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temporary:
|
||||||
|
subprocess.run([sys.executable, '-B', str(Path(__file__).with_name('make_icon.py')),
|
||||||
|
'--out', temporary], check=True)
|
||||||
|
for name in ('FinalToken.ico', 'FinalToken.png'):
|
||||||
|
self.assertEqual((ASSETS / name).read_bytes(), (Path(temporary) / name).read_bytes(), name)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user