diff --git a/lib/menu.ts b/lib/menu.ts index 9a05004..cd4ec1d 100644 --- a/lib/menu.ts +++ b/lib/menu.ts @@ -12,7 +12,7 @@ import { deleteRemote, mountRemote, unmountRemote } from './rclone/api' import { dialogGetMountPlugin, needsMountPlugin } from './rclone/mount' import { usePersistedStore, useStore } from './store' import { getLoadingTray, getMainTray, rebuildTrayMenu } from './tray' -import { lockWindows, openFullWindow, openTrayWindow, openWindow, unlockWindows } from './window' +import { lockWindows, openFullWindow, openWindow, unlockWindows } from './window' // Function to rebuild and update the menu export async function buildMenu() { @@ -343,7 +343,7 @@ export async function buildMenu() { id: 'jobs', text: 'Jobs', action: async () => { - await openTrayWindow({ + await openWindow({ name: 'Jobs', url: '/jobs', }) diff --git a/lib/tray.ts b/lib/tray.ts index 5618f27..728949d 100644 --- a/lib/tray.ts +++ b/lib/tray.ts @@ -3,28 +3,13 @@ import { MenuItem } from '@tauri-apps/api/menu' import { resolveResource } from '@tauri-apps/api/path' import type { TrayIconEvent } from '@tauri-apps/api/tray' import { TrayIcon } from '@tauri-apps/api/tray' -import { - PhysicalPosition, - PhysicalSize, - getAllWindows, - getCurrentWindow, -} from '@tauri-apps/api/window' +import { getAllWindows, getCurrentWindow } from '@tauri-apps/api/window' import { ask } from '@tauri-apps/plugin-dialog' import { platform } from '@tauri-apps/plugin-os' import { exit } from '@tauri-apps/plugin-process' import { buildMenu } from './menu' import { resetMainWindow } from './window' -let trayPosition = new PhysicalPosition(0, 0) -let traySize = new PhysicalSize(0, 0) - -export function getTrayRect() { - return { - position: trayPosition, - size: traySize, - } -} - export async function getMainTray() { return await TrayIcon.getById('main-tray') } @@ -50,9 +35,6 @@ export async function rebuildTrayMenu() { } async function onTrayAction(event: TrayIconEvent) { - trayPosition = event.rect.position - traySize = event.rect.size - if (event.type === 'Click') { console.log('Tray clicked:', event) diff --git a/lib/window.ts b/lib/window.ts index 399bf73..6d8b755 100644 --- a/lib/window.ts +++ b/lib/window.ts @@ -1,14 +1,8 @@ import { WebviewWindow } from '@tauri-apps/api/webviewWindow' -import { - LogicalSize, - PhysicalPosition, - PhysicalSize, - currentMonitor, - getAllWindows, -} from '@tauri-apps/api/window' +import { LogicalSize, PhysicalSize, currentMonitor, getAllWindows } from '@tauri-apps/api/window' import { platform } from '@tauri-apps/plugin-os' import { useStore } from './store' -import { getLoadingTray, getMainTray, getTrayRect } from './tray' +import { getLoadingTray, getMainTray } from './tray' export async function resetMainWindow() { const window = await getAllWindows().then((w) => w.find((w) => w.label === 'main')) @@ -103,67 +97,6 @@ export async function openWindow({ return w } -export async function openTrayWindow({ - name, - url, -}: { - name: string - url: string -}) { - if (platform() === 'windows') { - return await openWindow({ name, url }) - } - - const isFirstWindow = useStore.getState().firstWindow - - const w = new WebviewWindow(name, { - height: 0, - width: 0, - resizable: false, - visibleOnAllWorkspaces: true, - alwaysOnTop: true, - visible: true, - focus: true, - title: name, - decorations: false, - url: url, - }) - - // await getAllWindows() - // .then((w) => w.find((w) => w.label === 'main')) - // ?.then((w) => w?.setSize(new LogicalSize(400, 600))) - - await getMainTray().then((t) => t?.setVisible(false)) - await getLoadingTray().then((t) => t?.setVisible(true)) - await new Promise((resolve) => setTimeout(resolve, isFirstWindow ? 1000 : 150)) - await getLoadingTray().then((t) => t?.setVisible(false)) - await getMainTray().then((t) => t?.setVisible(true)) - - await w.hide() - - const windowSize = new LogicalSize(400, 600) - await w.setSize(windowSize) - - const trayRect = getTrayRect() - const windowPhysicalSize = windowSize.toPhysical(await w.scaleFactor()) - await w.setPosition( - new PhysicalPosition( - trayRect.position.x + trayRect.size.width / 2 - windowPhysicalSize.width / 2, - trayRect.position.y - ) - ) - - await w.show() - - await w.listen('tauri://blur', async () => { - await w.destroy() - }) - - useStore.setState({ firstWindow: false }) - - return w -} - export async function lockWindows(ids?: string[]) { const windows = await getAllWindows() const lockedWindows = ids ? windows.filter((w) => ids.includes(w.label)) : windows diff --git a/src/pages/Copy.tsx b/src/pages/Copy.tsx index cce45b6..298cd93 100644 --- a/src/pages/Copy.tsx +++ b/src/pages/Copy.tsx @@ -7,7 +7,7 @@ import { useSearchParams } from 'react-router-dom' import { getRemoteName } from '../../lib/format' import { getCopyFlags, getFilterFlags, getGlobalFlags, startCopy } from '../../lib/rclone/api' import { usePersistedStore } from '../../lib/store' -import { openTrayWindow } from '../../lib/window' +import { openWindow } from '../../lib/window' import OptionsSection from '../components/OptionsSection' import PathFinder from '../components/PathFinder' @@ -107,6 +107,9 @@ export default function Copy() { filterOptions, }) + // dummy delay to avoid waiting when opening the Jobs page + await new Promise((resolve) => setTimeout(resolve, 1500)) + setIsStarted(true) } catch (err) { console.error('Failed to start copy:', err) @@ -214,7 +217,7 @@ export default function Copy() { size="lg" color="primary" onPress={async () => { - await openTrayWindow({ name: 'Jobs', url: '/jobs' }) + await openWindow({ name: 'Jobs', url: '/jobs' }) // await getCurrentWindow().hide() await getCurrentWindow().destroy() diff --git a/src/pages/Sync.tsx b/src/pages/Sync.tsx index 7be5614..335c1f0 100644 --- a/src/pages/Sync.tsx +++ b/src/pages/Sync.tsx @@ -7,7 +7,7 @@ import { useSearchParams } from 'react-router-dom' import { getRemoteName } from '../../lib/format' import { getFilterFlags, getGlobalFlags, getSyncFlags, startSync } from '../../lib/rclone/api' import { usePersistedStore } from '../../lib/store' -import { openTrayWindow } from '../../lib/window' +import { openWindow } from '../../lib/window' import OptionsSection from '../components/OptionsSection' import PathFinder from '../components/PathFinder' @@ -107,6 +107,9 @@ export default function Sync() { filterOptions, }) + // dummy delay to avoid waiting when opening the Jobs page + await new Promise((resolve) => setTimeout(resolve, 1500)) + setIsStarted(true) } catch (err) { console.error('Failed to start sync:', err) @@ -214,7 +217,7 @@ export default function Sync() { size="lg" color="primary" onPress={async () => { - await openTrayWindow({ name: 'Jobs', url: '/jobs' }) + await openWindow({ name: 'Jobs', url: '/jobs' }) // await getCurrentWindow().hide() await getCurrentWindow().destroy()