-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathstore.ts
More file actions
85 lines (71 loc) · 2 KB
/
Copy pathstore.ts
File metadata and controls
85 lines (71 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import Store from "electron-store";
import { getUserDataDir } from "./env";
interface FocusSession {
mainRepoPath: string;
worktreePath: string;
branch: string;
originalBranch: string;
mainStashRef: string | null;
commitSha: string;
}
interface FocusStoreSchema {
sessions: Record<string, FocusSession>;
}
interface RendererStoreSchema {
[key: string]: string;
}
export interface WindowStateSchema {
x: number | undefined;
y: number | undefined;
width: number;
height: number;
isMaximized: boolean;
zoomLevel: number;
isFullScreen: boolean;
restoreFullScreenOnNextLaunch: boolean;
}
const userDataDir = getUserDataDir();
export const rendererStore = new Store<RendererStoreSchema>({
name: "renderer-storage",
cwd: userDataDir,
});
export const focusStore = new Store<FocusStoreSchema>({
name: "focus",
cwd: userDataDir,
defaults: { sessions: {} },
});
export type { FocusSession };
export const windowStateStore = new Store<WindowStateSchema>({
name: "window-state",
cwd: userDataDir,
defaults: {
x: undefined,
y: undefined,
width: 1200,
height: 600,
isMaximized: true,
zoomLevel: 0,
isFullScreen: false,
restoreFullScreenOnNextLaunch: false,
},
});
export function saveZoomLevel(level: number): void {
windowStateStore.set("zoomLevel", level);
}
export function saveFullScreenState(isFullScreen: boolean): void {
windowStateStore.set("isFullScreen", isFullScreen);
}
export function getFullScreenState(): boolean {
return windowStateStore.get("isFullScreen", false);
}
/**
* Set only when the app quits to install an update, so a fullscreen session
* is restored after the "restart to apply" handoff.
* A normal quit leaves it false and launches windowed.
*/
export function setRestoreFullScreenOnNextLaunch(restore: boolean): void {
windowStateStore.set("restoreFullScreenOnNextLaunch", restore);
}
export function getRestoreFullScreenOnNextLaunch(): boolean {
return windowStateStore.get("restoreFullScreenOnNextLaunch", false);
}