mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-23 18:38:12 +08:00
* ui scale preference * cleanup * add update ui scale message to SIDE_EFFECT_FREE_MESSAGES * fix mac title bar height * hide UI preference section on web * set % as unit of ui scale
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { writable } from "svelte/store";
|
|
|
|
import { type Editor } from "@graphite/editor";
|
|
import { type AppWindowPlatform, UpdatePlatform, UpdateViewportHolePunch, UpdateMaximized, UpdateFullscreen, UpdateUIScale } from "@graphite/messages";
|
|
|
|
export function createAppWindowState(editor: Editor) {
|
|
const { subscribe, update } = writable({
|
|
platform: "Web" as AppWindowPlatform,
|
|
maximized: false,
|
|
fullscreen: false,
|
|
viewportHolePunch: false,
|
|
uiScale: 1.0,
|
|
});
|
|
|
|
// Set up message subscriptions on creation
|
|
editor.subscriptions.subscribeJsMessage(UpdatePlatform, (updatePlatform) => {
|
|
update((state) => {
|
|
state.platform = updatePlatform.platform;
|
|
return state;
|
|
});
|
|
});
|
|
editor.subscriptions.subscribeJsMessage(UpdateMaximized, (updateMaximized) => {
|
|
update((state) => {
|
|
state.maximized = updateMaximized.maximized;
|
|
return state;
|
|
});
|
|
});
|
|
editor.subscriptions.subscribeJsMessage(UpdateFullscreen, (updateFullscreen) => {
|
|
update((state) => {
|
|
state.fullscreen = updateFullscreen.fullscreen;
|
|
return state;
|
|
});
|
|
});
|
|
editor.subscriptions.subscribeJsMessage(UpdateViewportHolePunch, (viewportHolePunch) => {
|
|
update((state) => {
|
|
state.viewportHolePunch = viewportHolePunch.active;
|
|
return state;
|
|
});
|
|
});
|
|
editor.subscriptions.subscribeJsMessage(UpdateUIScale, (uiScale) => {
|
|
update((state) => {
|
|
state.uiScale = uiScale.scale;
|
|
return state;
|
|
});
|
|
});
|
|
|
|
return {
|
|
subscribe,
|
|
};
|
|
}
|
|
export type AppWindowState = ReturnType<typeof createAppWindowState>;
|