FEAT: tray icon initial support

This commit is contained in:
valerio
2026-03-13 20:13:59 +01:00
parent 80fa105e31
commit 13f4cdb3f9
11 changed files with 352 additions and 46 deletions
+3 -1
View File
@@ -4,6 +4,8 @@ import { currentSettings } from './settings';
import { writable } from 'svelte/store';
import { get } from 'svelte/store';
const RELEASES_URL = 'https://download.blender.org/release/';
/**
* @typedef {Object} FileLink
* @property {string} version - The version string (e.g., "5.0.0")
@@ -32,7 +34,7 @@ export async function getBlenderReleases() {
const currentArch = settings.defaultArch;
try {
// Fetch the HTML page
const response = await fetch('https://download.blender.org/release/');
const response = await fetch(RELEASES_URL);
const html = await response.text();
// Parse the HTML
+3 -1
View File
@@ -12,6 +12,7 @@ import { ensureLibraryStructure, selectDirectory } from './file_utils.js';
* @property {string} [theme] - Theme ('light', 'dark')
* @property {boolean} [autoCreateShortcuts] - should smoothie create a shortcut to newly installed blender versions
* @property {boolean} [keepDownloadedArchives] - Whether to keep downloaded archives after extraction
* @property {boolean} [closeToTray] - Whether to close the window to the tray instead of exiting when the close button is clicked
*/
// Settings lazy store
@@ -32,7 +33,8 @@ export async function initSettings() {
defaultArch: detectedArch,
keepDownloadedArchives: false,
autoCreateShortcuts: true,
theme: 'light' //
theme: 'light', //
closeToTray: true
};
}
+49
View File
@@ -0,0 +1,49 @@
import { TrayIcon } from '@tauri-apps/api/tray';
import { getCurrentWindow } from '@tauri-apps/api/window';
import { currentSettings } from './settings';
import { get } from 'svelte/store';
import { Menu } from '@tauri-apps/api/menu';
const mainWindow = getCurrentWindow();
export async function setupTrayIcon() {
// Prevent the window from closing when the close button is clicked
mainWindow.onCloseRequested((event) => {
const settings = get(currentSettings);
if (settings.closeToTray) {
event.preventDefault();
mainWindow.hide();
}
});
const menu = await Menu.new({
items: [
{
id: 'toggle',
text: 'Show/Hide',
action: async () => {
const visible = await mainWindow.isVisible();
console.log(visible);
if (visible) {
mainWindow.hide();
} else {
mainWindow.show();
}
}
},
{
id: 'quit',
text: 'Quit',
action: () => {
mainWindow.destroy();
}
}
]
});
const options = {
menu,
menuOnLeftClick: true
};
return await TrayIcon.new(options);
}
+2
View File
@@ -1,5 +1,6 @@
<script>
import '@webtui/css/components/spinner.css';
import { setupTrayIcon } from '$lib/trayicon';
import { fade } from 'svelte/transition';
import { onMount } from 'svelte';
import { getSettings, currentSettings } from '$lib/settings.js';
@@ -46,6 +47,7 @@
await getSettings();
await getBlenderReleases();
await getInstalledVersions();
await setupTrayIcon();
initStoresListeners();
const elapsed = Date.now() - startTime;