forked from akai/readest
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { getCurrentWindow } from '@tauri-apps/api/window';
|
|
import { TauriEvent } from '@tauri-apps/api/event';
|
|
import { exit } from '@tauri-apps/plugin-process';
|
|
import { eventDispatcher } from './event';
|
|
|
|
export const tauriGetWindowLogicalPosition = async () => {
|
|
const currentWindow = getCurrentWindow();
|
|
const factor = await currentWindow.scaleFactor();
|
|
const physicalPos = await currentWindow.outerPosition();
|
|
return { x: physicalPos.x / factor, y: physicalPos.y / factor };
|
|
};
|
|
|
|
export const tauriHandleMinimize = async () => {
|
|
getCurrentWindow().minimize();
|
|
};
|
|
|
|
export const tauriHandleToggleMaximize = async () => {
|
|
getCurrentWindow().toggleMaximize();
|
|
};
|
|
|
|
export const tauriHandleClose = async () => {
|
|
getCurrentWindow().close();
|
|
};
|
|
|
|
export const tauriHandleOnCloseWindow = async (callback: () => void) => {
|
|
const currentWindow = getCurrentWindow();
|
|
return currentWindow.listen(TauriEvent.WINDOW_CLOSE_REQUESTED, async () => {
|
|
await callback();
|
|
console.log('exit app');
|
|
await exit(0);
|
|
});
|
|
};
|
|
|
|
export const tauriHandleToggleFullScreen = async () => {
|
|
const currentWindow = getCurrentWindow();
|
|
const isFullscreen = await currentWindow.isFullscreen();
|
|
const newIsFullscreen = !isFullscreen;
|
|
await currentWindow.setFullscreen(newIsFullscreen);
|
|
};
|
|
|
|
export const tauriHandleOnWindowFocus = async (callback: () => void) => {
|
|
const currentWindow = getCurrentWindow();
|
|
return currentWindow.listen(TauriEvent.WINDOW_FOCUS, async () => {
|
|
await callback();
|
|
});
|
|
};
|
|
|
|
export const tauriQuitApp = async () => {
|
|
await eventDispatcher.dispatch('quit-app');
|
|
await exit(0);
|
|
};
|