-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
97 lines (81 loc) · 2.53 KB
/
main.js
File metadata and controls
97 lines (81 loc) · 2.53 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
const { app, BrowserWindow, BrowserView, ipcMain, session, Menu } = require('electron');
const path = require('path');
const fs = require('fs');
let mainWindow;
let view;
app.on('ready', () => {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
icon: path.join(__dirname, 'icon.ico'),
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
nodeIntegration: false,
},
});
Menu.setApplicationMenu(null);
mainWindow.loadFile('index.html');
mainWindow.webContents.setZoomFactor(0.8);
// Create a BrowserView for main content with persistent cookies.
view = new BrowserView({ webPreferences: { partition: 'persist:persistent' } });
mainWindow.setBrowserView(view);
updateViewBounds();
view.webContents.loadURL('https://workspace.org');
ipcMain.on('navigate', (event, url) => {
view.webContents.loadURL(url);
});
// Open a modal popup for info or logout.
ipcMain.on('open-popup', (event, popupType) => {
const popup = new BrowserWindow({
width: 350,
height: 250,
modal: true,
parent: mainWindow,
frame: false,
// Solid background (no transparency)
alwaysOnTop: true,
webPreferences: {
preload: path.join(__dirname, 'popupPreload.js'),
contextIsolation: true,
nodeIntegration: false,
},
});
popup.loadFile('popup.html');
popup.webContents.once('did-finish-load', () => {
popup.webContents.send('popup-type', popupType);
});
});
ipcMain.on('close-popup', (event) => {
const win = BrowserWindow.fromWebContents(event.sender);
if (win) {
win.close();
}
});
ipcMain.on('clear-cookies', async (event) => {
try {
const partitionPath = path.join(app.getPath('userData'), 'Partitions', 'persistent');
console.log('Partition Path:', partitionPath);
const customSession = session.fromPartition('persist:persistent');
customSession.clearStorageData([], (data) => {
console.log('Storage Data Cleared:', data);
});
} catch (error) {
console.error('Failed to clear cookies:', error);
event.reply('cookies-cleared', false);
}
});
ipcMain.on('quit-app', () => {
app.quit();
});
mainWindow.on('resize', updateViewBounds);
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
function updateViewBounds() {
const [width, height] = mainWindow.getSize();
view.setBounds({ x: 0, y: 50, width: width - 10, height: height - 80 });
}