-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
642 lines (642 loc) Β· 26.4 KB
/
main.js
File metadata and controls
642 lines (642 loc) Β· 26.4 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const electron_1 = require("electron");
const path = __importStar(require("path"));
const http = __importStar(require("http"));
const socket_io_1 = require("socket.io");
const os = __importStar(require("os"));
const fs = __importStar(require("fs"));
const CryptoJS = __importStar(require("crypto-js"));
const child_process_1 = require("child_process");
const crypto = __importStar(require("crypto"));
const events_1 = require("events");
const ghostBus = new events_1.EventEmitter();
// State
let win = null;
let tray = null;
let io = null;
let lastClipboardText = readBestClipboardText();
let isQuitting = false;
let syncKey = 'CodebLink-Default-Key';
const pollListeners = new Set();
// π¦ GHOST VAULT: Holds the last message for 60s for phones "between" polls
let ghostVault = null;
// π PENDING DOWNLOADS: token β file path, expires after 10 minutes
const pendingDownloads = new Map();
// Internal bus: when clipboard changes, tell all long-polling background clients
ghostBus.on('broadcast', (text) => {
// Only fill the vault for plain clipboard text β file payloads are one-shot
// (they carry a single-use download token) and must NOT be vaulted, otherwise
// a re-poll after the live listener fires would deliver the same token again
// and trigger a duplicate download.
const isFileBroadcast = text.startsWith('{"type":"file"');
if (!isFileBroadcast) {
ghostVault = { content: text, timestamp: Date.now() };
}
for (const listener of pollListeners) {
listener(text);
}
});
const iconPath = path.join(__dirname, 'icon.png');
const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL'];
// βββ showMainWindow (workspace-shift trick, same as whatsapp project) ββββ
function showMainWindow() {
if (!win || win.isDestroyed()) {
createWindow();
return;
}
const wasVisible = win.isVisible();
// If visible on another workspace, hide first so it re-appears on the
// CURRENT workspace (same trick used in the whatsapp project).
if (wasVisible) {
win.hide();
}
if (win.isMinimized()) {
win.restore();
}
win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
win.show();
win.moveTop();
win.focus();
// Unpin after it's safely shown on the current workspace
setTimeout(() => {
if (win && !win.isDestroyed()) {
win.setVisibleOnAllWorkspaces(false, { visibleOnFullScreen: true });
}
}, 300);
}
// βββ Single Instance Lock ββββββββββββββββββββββββββββββββββββββββββββββββ
const gotLock = electron_1.app.requestSingleInstanceLock();
if (!gotLock) {
electron_1.app.quit();
}
else {
electron_1.app.on('second-instance', () => {
showMainWindow();
});
electron_1.app.whenReady().then(() => {
createWindow();
createTray();
startSocketServer();
startClipboardPolling();
});
}
// βββ Window ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function createWindow() {
const primaryDisplay = electron_1.screen.getPrimaryDisplay();
const { width, height } = primaryDisplay.workAreaSize || primaryDisplay.size;
win = new electron_1.BrowserWindow({
x: 0,
y: 0,
width,
height,
icon: fs.existsSync(iconPath) ? iconPath : undefined,
show: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
contextIsolation: false,
},
});
electron_1.Menu.setApplicationMenu(null);
win.removeMenu();
win.once('ready-to-show', () => {
if (win) {
// Explicitly set window icon on Linux so the taskbar/dock shows it
if (process.platform === 'linux' && fs.existsSync(iconPath)) {
const { nativeImage } = require('electron');
win.setIcon(nativeImage.createFromPath(iconPath));
}
win.maximize();
win.show();
}
});
win.on('close', (event) => {
if (!isQuitting) {
event.preventDefault();
win?.hide();
}
});
win.on('closed', () => { win = null; });
if (VITE_DEV_SERVER_URL) {
win.loadURL(VITE_DEV_SERVER_URL);
if (process.env.NODE_ENV !== 'production') {
win.webContents.openDevTools();
}
}
else {
// __dirname is dist-electron/ inside the asar; dist/ is one level up at asar root
win.loadFile(path.join(__dirname, '..', 'dist', 'index.html'));
}
}
// βββ Tray ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function createTray() {
if (!fs.existsSync(iconPath)) {
console.log('Tray icon not found. Add icon.png to enable system tray.');
return;
}
try {
const { nativeImage } = require('electron');
const image = nativeImage.createFromPath(iconPath);
if (image.isEmpty()) {
console.error('Failed to load tray icon: image is empty at', iconPath);
return;
}
// Resize to standard Linux tray icon size (22Γ22) so it renders cleanly
const trayImage = image.resize({ width: 22, height: 22 });
tray = new electron_1.Tray(trayImage);
const contextMenu = electron_1.Menu.buildFromTemplate([
{
label: 'Show Codeb Link',
click: () => { showMainWindow(); }
},
{ type: 'separator' },
{
label: 'Quit',
click: () => {
isQuitting = true;
if (tray) {
tray.destroy();
tray = null;
}
electron_1.app.quit();
}
},
]);
tray.setToolTip('Codeb Link');
tray.setContextMenu(contextMenu);
const closeTrayMenuSoon = () => {
setTimeout(() => { if (tray)
tray.closeContextMenu(); }, 0);
};
// Left click β open window on current workspace
tray.on('click', (event) => {
const button = event && event.button;
if (button === 2 || button === 'right')
return;
showMainWindow();
closeTrayMenuSoon();
});
// Right click β show context menu
tray.on('right-click', () => {
tray.popUpContextMenu(contextMenu);
});
// GNOME extensions may emit only mouse-up for secondary click
tray.on('mouse-up', (event) => {
const button = event && event.button;
if (button === 2 || button === 'right') {
tray.popUpContextMenu(contextMenu);
}
});
}
catch (e) {
console.warn('Tray failed:', e);
}
}
let ghostLastSeen = 0;
let lastReportedMode = 'none';
function updateOverallStatus() {
const isSocketConnected = io ? io.sockets.sockets.size > 0 : false;
const isGhostActive = (Date.now() - ghostLastSeen) < 40000;
let currentMode = 'none';
if (isSocketConnected)
currentMode = 'socket';
else if (isGhostActive)
currentMode = 'ghost';
if (currentMode !== lastReportedMode) {
lastReportedMode = currentMode;
win?.webContents.send('overall-connection-status', {
connected: currentMode !== 'none',
mode: currentMode
});
}
}
// Periodically check pulse
setInterval(updateOverallStatus, 5000);
// βββ Socket.io Server βββββββββββββββββββββββββββββββββββββββββββββββββββ
function startSocketServer() {
const server = http.createServer((req, res) => {
res.setHeader('Access-Control-Allow-Origin', '*');
// Log EVERY incoming HTTP request for diagnostics
if (req.url?.startsWith('/api/')) {
// console.log(`π‘ [PC Server] Incoming: ${req.method} ${req.url}`);
}
// ββ POST /api/clipboard (Android β PC) ββββββββββββββββββββββββββββββ
if (req.method === 'POST' && req.url === '/api/clipboard') {
ghostLastSeen = Date.now();
updateOverallStatus();
let body = '';
req.on('data', (chunk) => { body += chunk; });
req.on('end', () => {
try {
const { data } = JSON.parse(body);
const bytes = CryptoJS.AES.decrypt(data, syncKey);
const text = bytes.toString(CryptoJS.enc.Utf8);
if (text && text !== lastClipboardText) {
lastClipboardText = text;
writeSystemClipboard(text);
win?.webContents.send('clipboard-received', text);
process.stdout.write(`\rπ [BG Sync] Clipboard received from Android\n`);
}
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ ok: true }));
}
catch (e) {
res.writeHead(400);
res.end(JSON.stringify({ error: 'Failed' }));
}
});
return;
// ββ POST /api/ghost/receipt (Android β PC confirmation) βββββββββββββ
}
else if (req.method === 'POST' && req.url === '/api/ghost/receipt') {
let body = '';
req.on('data', (chunk) => { body += chunk; });
req.on('end', () => {
try {
const { file } = JSON.parse(body);
process.stdout.write(`\rβ
[Ghost] Phone confirmed receipt of: ${file}\n`);
res.writeHead(200);
res.end(JSON.stringify({ ok: true }));
}
catch (e) {
res.writeHead(400);
res.end();
}
});
return;
// ββ GET /api/clipboard/poll (PC β Android long-poll) ββββββββββββββββ
}
else if (req.method === 'GET' && req.url === '/api/clipboard/poll') {
res.setHeader('Content-Type', 'application/json');
ghostLastSeen = Date.now();
updateOverallStatus();
const sendResponse = (content) => {
let responseBody;
if (content.startsWith('{"type":"file"')) {
responseBody = content;
}
else {
const encrypted = CryptoJS.AES.encrypt(content, syncKey).toString();
responseBody = JSON.stringify({ data: encrypted });
}
res.writeHead(200);
res.end(responseBody);
process.stdout.write(`\rπ [Ghost] Dispatching update (Vault/Live) β\n`);
};
// 1. Instant Vault Check
if (ghostVault && (Date.now() - ghostVault.timestamp < 60000)) {
sendResponse(ghostVault.content);
ghostVault = null;
return;
}
process.stdout.write(`\rπ°οΈ [Ghost] Background device waiting...\n`);
// Hold connection open until clipboard changes or 25s timeout
const timeoutId = setTimeout(() => {
if (!res.writableEnded) {
res.writeHead(204); // No content β tell phone to re-poll immediately
res.end();
}
}, 25000);
const onClipChange = (content) => {
clearTimeout(timeoutId);
if (!res.writableEnded) {
sendResponse(content);
}
};
pollListeners.add(onClipChange);
req.on('close', () => {
clearTimeout(timeoutId);
pollListeners.delete(onClipChange);
});
// ββ GET /api/dl/:token (Phone streams file from PC) ββββββββββββββββββ
}
else if (req.method === 'GET' && req.url?.startsWith('/api/dl/')) {
const token = req.url.slice('/api/dl/'.length).split('?')[0];
const entry = pendingDownloads.get(token);
if (!entry || Date.now() > entry.expires) {
pendingDownloads.delete(token);
res.writeHead(404);
res.end('Not found');
return;
}
// Consume the token immediately β any concurrent or subsequent request for
// the same token gets a 404, preventing duplicate downloads.
pendingDownloads.delete(token);
try {
const stat = fs.statSync(entry.filePath);
res.writeHead(200, {
'Content-Type': 'application/octet-stream',
'Content-Length': stat.size,
'Content-Disposition': 'attachment',
});
const stream = fs.createReadStream(entry.filePath);
stream.pipe(res);
stream.on('error', () => { if (!res.writableEnded)
res.end(); });
}
catch (e) {
res.writeHead(500);
res.end();
}
return;
// ββ Everything else: let socket.io handle ββββββββββββββββββββββββββββ
}
else if (!req.url?.startsWith('/socket.io')) {
res.writeHead(404);
res.end();
}
});
io = new socket_io_1.Server(server, {
cors: { origin: '*', methods: ['GET', 'POST'] },
// Base64 inflates payload size (~33%).
maxHttpBufferSize: 500 * 1024 * 1024,
// Extremely generous timeouts to prevent Android power-management from
// triggering false disconnects during Wi-Fi "naps".
pingInterval: 10000,
pingTimeout: 60000,
connectTimeout: 30000,
// Explicitly allow both transports for better fallback
transports: ['polling', 'websocket'],
allowEIO3: true,
});
// Plain WebSocket support for the Native Android Background Service
// This allows the "Ghost" service to receive updates even when JS is killed.
server.on('upgrade', (request, socket, head) => {
if (request.url === '/bg-sync') {
// We can handle plain WS here if needed, but for now
// Socket.io already handles the 'upgrade' event.
// I will ensure the broadcast hits the background service too.
}
});
io.on('connection', (socket) => {
console.log('π± Connected:', socket.id);
win?.webContents.send('device-connected', socket.id);
// Immediately read fresh system clipboard and sync it to the newly connected device
const freshText = readBestClipboardText();
if (freshText) {
lastClipboardText = freshText;
const encrypted = CryptoJS.AES.encrypt(freshText, syncKey).toString();
socket.emit('clipboard-received', encrypted);
console.log('β‘ Initial sync sent to new connection');
}
socket.on('sync-key', (key, ack) => {
const incoming = typeof key === 'string' ? key : '';
if (incoming.length > 0) {
syncKey = incoming;
const keyId = CryptoJS.MD5(syncKey).toString().slice(0, 8);
console.log(`π Sync key updated from phone session (id=${keyId})`);
ack?.({ ok: true, keyId });
// After key sync, send the latest clipboard snapshot immediately so
// phone receives at least one known-good encrypted state.
const current = readBestClipboardText();
if (current) {
const encrypted = CryptoJS.AES.encrypt(current, syncKey).toString();
socket.emit('clipboard-received', encrypted);
}
}
else {
ack?.({ ok: false });
}
});
socket.on('clipboard-update', (encryptedData) => {
try {
const bytes = CryptoJS.AES.decrypt(encryptedData, syncKey);
const data = bytes.toString(CryptoJS.enc.Utf8);
if (data && data !== lastClipboardText) {
lastClipboardText = data;
writeSystemClipboard(data);
win?.webContents.send('clipboard-received', data);
}
}
catch (e) {
console.error('Decrypt failed');
}
});
socket.on('file-received', (fileData, ack) => {
try {
const downloadsPath = path.join(os.homedir(), 'Downloads');
if (!fs.existsSync(downloadsPath))
fs.mkdirSync(downloadsPath, { recursive: true });
const safeName = sanitizeFileName(fileData.name || `shared_${Date.now()}`);
const filePath = resolveUniqueFilePath(downloadsPath, safeName);
// Convert base64 data to buffer
const buffer = Buffer.from(fileData.data ?? '', 'base64');
fs.writeFileSync(filePath, buffer);
console.log(`π File saved: ${filePath}`);
win?.webContents.send('file-saved', { name: path.basename(filePath), path: filePath });
ack?.({ ok: true, name: path.basename(filePath) });
}
catch (e) {
console.error('File save failed:', e);
ack?.({ ok: false, error: e instanceof Error ? e.message : 'File save failed' });
}
});
socket.on('file-delivered-phone', (info) => {
win?.webContents.send('file-delivered-phone', info || {});
});
socket.on('phone-log', (line) => {
process.stdout.write(`\rπ± [Phone] ${line}\n`);
});
socket.on('disconnect', () => {
win?.webContents.send('device-disconnected', socket.id);
});
});
server.listen(4321, '0.0.0.0', () => {
console.log(`β
Server ready on 4321`);
});
}
// βββ Clipboard Polling ββββββββββββββββββββββββββββββββββββββββββββββββββ
function startClipboardPolling() {
setInterval(() => {
try {
const broadcastClipboard = (text) => {
lastClipboardText = text;
const encrypted = CryptoJS.AES.encrypt(text, syncKey).toString();
io?.emit('clipboard-received', encrypted);
win?.webContents.send('clipboard-received', text);
// Signal the long-polling HTTP listeners
ghostBus.emit('broadcast', text);
};
const text = readBestClipboardText();
if (text && text !== lastClipboardText) {
broadcastClipboard(text);
}
}
catch (e) {
console.warn('Polling glitch (ignoring):', e);
}
}, 1000);
}
// βββ IPC βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
electron_1.ipcMain.handle('get-local-ip', () => getLocalIp());
electron_1.ipcMain.handle('read-local-clipboard', () => {
return readBestClipboardText() || '';
});
electron_1.ipcMain.on('set-sync-key', (_event, key) => {
syncKey = key || 'CodebLink-Default-Key';
});
electron_1.ipcMain.on('send-clipboard', (_event, text) => {
if (!text)
return;
// Force update the cache so the next poll doesn't see this as a "new" change
lastClipboardText = text;
electron_1.clipboard.writeText(text);
const encrypted = CryptoJS.AES.encrypt(text, syncKey).toString();
// Broadcast to ALL connected phones immediately
io?.emit('clipboard-received', encrypted);
ghostBus.emit('broadcast', text);
console.log('π’ Manual sync: Broad-casted clipboard to phone(s)');
});
electron_1.ipcMain.on('send-file-to-phone', (_event, fileData) => {
if (!io)
return;
const hasSocketClients = io.sockets.sockets.size > 0;
if (fileData.path) {
// Large-file path: generate a one-time download token and let the phone
// stream the file over HTTP β no base64 buffering in memory on either side.
const token = crypto.randomBytes(16).toString('hex');
pendingDownloads.set(token, { filePath: fileData.path, expires: Date.now() + 10 * 60 * 1000 });
const localIp = getLocalIp();
const url = `http://${localIp}:4321/api/dl/${token}`;
io.emit('file-to-phone', { name: fileData.name, type: fileData.type, url });
// Ghost mode: only broadcast via HTTP poll when no socket client is connected β
// a connected phone receives the file via socket above; double-emitting causes duplicates.
if (!hasSocketClients) {
ghostBus.emit('broadcast', JSON.stringify({ type: 'file', name: fileData.name, mimeType: fileData.type, url }));
}
win?.webContents.send('file-send-status', { ok: true, name: fileData.name });
}
else if (fileData.data) {
// Legacy base64 path (kept for backward compat / very small files)
io.emit('file-to-phone', { name: fileData.name, type: fileData.type, data: fileData.data });
if (!hasSocketClients) {
const ghostPayload = { type: 'file', name: fileData.name, data: fileData.data };
ghostBus.emit('broadcast', JSON.stringify(ghostPayload));
}
win?.webContents.send('file-send-status', { ok: true, name: fileData.name });
}
});
// βββ Helpers βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function getLocalIp() {
const interfaces = os.networkInterfaces();
for (const name of Object.keys(interfaces)) {
const net = interfaces[name];
if (net) {
for (const iface of net) {
if (iface.family === 'IPv4' && !iface.internal)
return iface.address;
}
}
}
return '127.0.0.1';
}
function tryReadCommand(command) {
try {
const output = (0, child_process_1.execSync)(command, {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'ignore'],
timeout: 500,
maxBuffer: 1024 * 1024,
});
return output.trim();
}
catch {
return '';
}
}
// Write text to the system clipboard in a way that BOTH X11 and Wayland-native
// apps can read it. Electron's clipboard.writeText() only writes to the XWayland
// buffer; wl-copy (or xclip) propagates it to the Wayland clipboard protocol.
function writeSystemClipboard(text) {
electron_1.clipboard.writeText(text); // X11 / Electron fallback
if (process.platform !== 'linux')
return;
const r = (0, child_process_1.spawnSync)('wl-copy', [], {
input: text,
encoding: 'utf8',
timeout: 1000,
stdio: ['pipe', 'ignore', 'ignore'],
});
if (r.status !== 0) {
(0, child_process_1.spawnSync)('xclip', ['-selection', 'clipboard'], {
input: text,
encoding: 'utf8',
timeout: 1000,
stdio: ['pipe', 'ignore', 'ignore'],
});
}
}
function readBestClipboardText() {
const direct = electron_1.clipboard.readText('clipboard').trim();
if (direct)
return direct;
if (process.platform !== 'linux')
return '';
// Wayland clipboard backend
const wl = tryReadCommand('wl-paste -n');
if (wl)
return wl;
// X11 clipboard backend
const xclip = tryReadCommand('xclip -selection clipboard -o');
if (xclip)
return xclip;
const xsel = tryReadCommand('xsel --clipboard --output');
if (xsel)
return xsel;
return '';
}
function sanitizeFileName(name) {
const cleaned = name.replace(/[\\/:*?"<>|]/g, '_').replace(/\s+/g, ' ').trim();
return cleaned || `shared_${Date.now()}`;
}
function resolveUniqueFilePath(dir, fileName) {
const ext = path.extname(fileName);
const base = ext ? fileName.slice(0, -ext.length) : fileName;
let n = 0;
while (true) {
const candidateName = n === 0 ? `${base}${ext}` : `${base} (${n})${ext}`;
const candidatePath = path.join(dir, candidateName);
if (!fs.existsSync(candidatePath))
return candidatePath;
n += 1;
}
}
// βββ App Lifecycle ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
electron_1.app.on('before-quit', () => {
isQuitting = true;
if (tray)
tray.destroy();
});
electron_1.app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
// Keep alive for tray
}
});
electron_1.app.on('activate', () => {
if (win === null)
createWindow();
});