-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
94 lines (78 loc) · 2.41 KB
/
main.js
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
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true;
const electron= require("electron")
const {app, BrowserWindow, screen, shell} = electron;
const path = require('path')
const isdev = !app.isPackaged
const { ipcMain } = require('electron');
const Store = require('electron-store');
const fs = require('fs');
const store = new Store();
ipcMain.on('save-user', (event, user) => {
const data = {
accessToken: user.accessToken,
user: user.user,
};
store.set('userData', JSON.stringify(data));
});
ipcMain.on('get-user', (event) => {
const userData = store.get('userData');
if (userData) {
event.returnValue = JSON.parse(userData);
} else {
event.returnValue = null;
}
});
ipcMain.handle('clear-user', async (event) => {
try {
await store.clear();
console.log("user model cleared");
} catch (error) {
console.error("Failed to clear user model:", error);
}
});
function createWindow(){
const { width, height } = screen.getPrimaryDisplay().workAreaSize;
const win = new BrowserWindow({
width:width,
height:height,
webPreferences:{
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
// preload: path.join(__dirname, 'preload.js')
},
icon: path.join(__dirname, './src/assets/images/icon.png')
})
win.loadFile(path.join(__dirname, 'public', 'index.html'))
const colorsFilePath = path.join(__dirname, 'src', 'assets', 'theme', 'base','colors.js');
fs.watchFile(colorsFilePath, (curr, prev) => {
try {
const colors = JSON.parse(fs.readFileSync(colorsFilePath, 'utf8'));
win.webContents.send('update-colors', colors);
} catch (error) {
console.error('Error reading or parsing colors.json:', error);
}
});
}
if(isdev){
require('electron-reload')(__dirname, {
electron:path.join(__dirname, 'node_modules', '.bin', 'electron')
})
}
app.whenReady().then(createWindow)
app.on('window-all-closed', ()=>{
if(process.platform !== 'darwin'){
app.quit()
}
})
app.on('activate', ()=>{
if(BrowserWindow.getAllWindows().length == 0){
createWindow();
}
})
app.on('web-contents-created', (_, contents) => {
contents.on('new-window', (event, url) => {
event.preventDefault();
shell.openExternal(url);
});
});