Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
76 lines (64 loc) · 2.09 KB
/
Copy pathmain.js
File metadata and controls
76 lines (64 loc) · 2.09 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
const { app, BrowserWindow, ipcMain, dialog, screen, shell } = require('electron');
const path = require('path');
const fs = require('fs');
const os = require('os');
function createWindow() {
// Target content width: 670px (excluding body padding/margins). With current body padding (18px each side)
// we start around 670 + 36 = 706px and then auto-fit to actual layout after load.
const win = new BrowserWindow({
width: 1280,
height: 920,
minWidth: 980,
minHeight: 760,
useContentSize: true,
backgroundColor: '#f6f3ea',
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
}
});
win.loadFile(path.join(__dirname, 'index.html'));
win.webContents.on('did-finish-load', async () => {
try {
const { width: screenW, height: screenH } = screen.getPrimaryDisplay().workAreaSize;
const { w, h } = await win.webContents.executeJavaScript(`
({
w: Math.ceil(document.documentElement.scrollWidth),
h: Math.ceil(document.documentElement.scrollHeight)
})
`);
// Add a small margin; cap to available screen size
const targetW = Math.min(w + 24, screenW);
const targetH = Math.min(h + 24, screenH);
win.setContentSize(targetW, targetH);
} catch (_) {
// ignore sizing errors
}
});
}
ipcMain.handle('pick-file', async () => {
const res = await dialog.showOpenDialog({
properties: ['openFile', 'multiSelections']
});
return res;
});
ipcMain.handle('pick-folder', async () => {
const res = await dialog.showOpenDialog({
properties: ['openDirectory']
});
return res;
});
// Backward-compatible alias (some renderer code may still call this)
ipcMain.handle('pick-directory', async () => {
const res = await dialog.showOpenDialog({
properties: ['openDirectory']
});
return res;
});
ipcMain.handle('open-logs-folder', async () => {
const logsDir = path.join(os.homedir(), '.config', 'server_uploader', 'logs');
fs.mkdirSync(logsDir, { recursive: true });
await shell.openPath(logsDir);
return logsDir;
});
app.whenReady().then(createWindow);