forked from selimaj-dev/linear-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
109 lines (93 loc) · 2.95 KB
/
index.js
File metadata and controls
109 lines (93 loc) · 2.95 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const { app, BrowserWindow, session, globalShortcut } = require('electron');
const fs = require('fs');
const path = require('path');
let stateFilePath;
const loadWindowState = () => {
if (!stateFilePath) return {};
try {
const raw = fs.readFileSync(stateFilePath, 'utf8');
const parsed = JSON.parse(raw);
const { width, height, x, y } = parsed;
if (Number.isFinite(width) && Number.isFinite(height)) {
return {
width,
height,
x: Number.isFinite(x) ? x : undefined,
y: Number.isFinite(y) ? y : undefined,
};
}
} catch (_) {
// Ignore malformed or missing state and fall back to defaults.
}
return {};
};
const saveWindowState = (bounds) => {
if (!stateFilePath || !bounds) return;
try {
fs.mkdirSync(path.dirname(stateFilePath), { recursive: true });
fs.writeFileSync(stateFilePath, JSON.stringify(bounds), 'utf8');
} catch (_) {
// Persisting state is best-effort; ignore write failures.
}
};
const createWindow = () => {
let state = {};
const focusedWindow = BrowserWindow.getFocusedWindow();
if (focusedWindow) {
const bounds = focusedWindow.getBounds();
state = {
width: bounds.width,
height: bounds.height,
x: bounds.x + 30,
y: bounds.y + 30
};
} else {
state = loadWindowState();
}
const windowOptions = {
width: state.width || 800,
height: state.height || 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
},
};
if (Number.isFinite(state.x) && Number.isFinite(state.y)) {
windowOptions.x = state.x;
windowOptions.y = state.y;
}
const win = new BrowserWindow(windowOptions);
win.setMenu(null);
win.loadURL('https://linear.app/login');
win.on('close', () => {
saveWindowState(win.getBounds());
});
};
app.whenReady().then(() => {
stateFilePath = path.join(app.getPath('userData'), 'window-state.json');
session.defaultSession.setPermissionRequestHandler((_, permission, callback, details) => {
const origin = details?.requestingUrl || '';
const isLinear = origin.startsWith('https://linear.app');
if (permission === 'notifications' && isLinear) {
return callback(true);
}
return callback(false);
});
createWindow();
app.on('browser-window-focus', () => {
globalShortcut.register('CommandOrControl+Shift+N', createWindow);
});
app.on('browser-window-blur', () => {
globalShortcut.unregister('CommandOrControl+Shift+N');
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});