desktop 앱 적용
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { WebviewWindow } from '@tauri-apps/api/webviewWindow';
|
||||
import type { FloatingWidgetInstance } from '@frontend/types/floatingWidget';
|
||||
|
||||
const widgetWindows = new Map<string, WebviewWindow>();
|
||||
|
||||
function widgetUrl(instance: FloatingWidgetInstance): string {
|
||||
const params = new URLSearchParams({
|
||||
id: instance.id,
|
||||
rows: String(instance.rows),
|
||||
cols: String(instance.cols),
|
||||
width: String(instance.width),
|
||||
height: String(instance.height),
|
||||
});
|
||||
if (instance.rowFr?.length) params.set('rowFr', instance.rowFr.join(','));
|
||||
if (instance.colFr?.length) params.set('colFr', instance.colFr.join(','));
|
||||
params.set('slots', JSON.stringify(instance.slots));
|
||||
return `widget.html?${params.toString()}`;
|
||||
}
|
||||
|
||||
export async function openWidgetWindow(instance: FloatingWidgetInstance): Promise<void> {
|
||||
const label = `widget-${instance.id}`;
|
||||
const existing = widgetWindows.get(instance.id) ?? (await WebviewWindow.getByLabel(label));
|
||||
if (existing) {
|
||||
await existing.setFocus();
|
||||
widgetWindows.set(instance.id, existing);
|
||||
return;
|
||||
}
|
||||
|
||||
const win = new WebviewWindow(label, {
|
||||
url: widgetUrl(instance),
|
||||
title: 'GoldenChart Widget',
|
||||
width: instance.width,
|
||||
height: instance.height,
|
||||
minWidth: 320,
|
||||
minHeight: 240,
|
||||
decorations: true,
|
||||
resizable: true,
|
||||
center: false,
|
||||
x: instance.position.x,
|
||||
y: instance.position.y,
|
||||
});
|
||||
|
||||
widgetWindows.set(instance.id, win);
|
||||
|
||||
void win.once('tauri://destroyed', () => {
|
||||
widgetWindows.delete(instance.id);
|
||||
});
|
||||
}
|
||||
|
||||
export async function closeWidgetWindow(id: string): Promise<void> {
|
||||
const label = `widget-${id}`;
|
||||
const win = widgetWindows.get(id) ?? (await WebviewWindow.getByLabel(label));
|
||||
if (win) {
|
||||
await win.close();
|
||||
widgetWindows.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
export async function focusWidgetWindow(id: string): Promise<void> {
|
||||
const label = `widget-${id}`;
|
||||
const win = widgetWindows.get(id) ?? (await WebviewWindow.getByLabel(label));
|
||||
if (win) await win.setFocus();
|
||||
}
|
||||
Reference in New Issue
Block a user