fix: ensure application uses correct system tray icon when bootstrapping

This commit checks on bootstrap what the currently configured theme
of the user is and loads the system tray icon in its corresponding
variation.

Unfortunately, MacOS doesn't seem to automatically swap out the icons
based on the system's theme, so we have to do it manually with two
different SVG files.

Another gotcha here is that, it doesn't seem to be possible to change
the system tray icon at runtime. When trying to reassign the `icon.source`
based on a newly selected theme, the icon disappears altogether.
The application also doesn't get notified when a user switches the theme
inside the operating system, requiring her to switch to the same theme
manually unless restarted.

Last but not least, using SVG files instead of PNG doesn't seem to solve
the problem that the icon is rendered blurry. I've looked in the docs
but there doesn't seem to be an option to have any influence on that...
This commit is contained in:
Pascal Precht 2021-02-10 11:55:57 +01:00 committed by Iuri Matias
parent 8977ba4931
commit 040b2020dd
3 changed files with 9 additions and 1 deletions

View File

@ -233,7 +233,9 @@ ApplicationWindow {
SystemTrayIcon {
id: systemTray
visible: true
icon.source: "shared/img/status-logo.png"
icon.source: applicationWindow.Universal.theme === Universal.Dark ?
"shared/img/status-logo.svg" :
"shared/img/status-logo-light-theme.svg";
menu: Menu {
MenuItem {
//% "Quit"

View File

@ -0,0 +1,3 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M4 0C1.79086 0 0 1.79086 0 4V12C0 14.2091 1.79086 16 4 16H12C14.2091 16 16 14.2091 16 12V4C16 1.79086 14.2091 0 12 0H4ZM8.05238 7.82632C8.51994 7.87386 8.9875 7.9214 9.56233 7.89013C11.12 7.80533 12.0637 7.02391 11.9967 5.85609C11.9286 4.66792 10.6731 3.93601 9.41702 4.00441C7.37019 4.11602 5.86497 5.87191 5.69521 7.87915C5.97317 7.81669 6.25643 7.77768 6.54167 7.76256C7.11684 7.73121 7.58461 7.77876 8.05238 7.82632ZM4.00321 10.263C4.06851 11.3748 5.27105 12.06 6.47436 11.9959C8.43531 11.8916 9.87724 10.2482 10.0396 8.36968C9.77312 8.42816 9.50181 8.46467 9.2287 8.4788C8.67783 8.50817 8.22977 8.46366 7.78168 8.41914C7.33378 8.37464 6.88587 8.33014 6.33524 8.35943C4.84302 8.43881 3.93899 9.16999 4.00321 10.263Z" fill="#2F2F2F"/>
</svg>

After

Width:  |  Height:  |  Size: 890 B

View File

@ -0,0 +1,3 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M4 0C1.79086 0 0 1.79086 0 4V12C0 14.2091 1.79086 16 4 16H12C14.2091 16 16 14.2091 16 12V4C16 1.79086 14.2091 0 12 0H4ZM8.05238 7.82632C8.51994 7.87386 8.9875 7.9214 9.56233 7.89013C11.12 7.80533 12.0637 7.02391 11.9967 5.85609C11.9286 4.66792 10.6731 3.93601 9.41702 4.00441C7.37019 4.11602 5.86497 5.87191 5.69521 7.87915C5.97317 7.81669 6.25643 7.77768 6.54167 7.76256C7.11684 7.73121 7.58461 7.77876 8.05238 7.82632ZM4.00321 10.263C4.06851 11.3748 5.27105 12.06 6.47436 11.9959C8.43531 11.8916 9.87724 10.2482 10.0396 8.36968C9.77312 8.42816 9.50181 8.46467 9.2287 8.4788C8.67783 8.50817 8.22977 8.46366 7.78168 8.41914C7.33378 8.37464 6.88587 8.33014 6.33524 8.35943C4.84302 8.43881 3.93899 9.16999 4.00321 10.263Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 888 B