-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
149 lines (136 loc) · 3.49 KB
/
Copy pathmain.js
File metadata and controls
149 lines (136 loc) · 3.49 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
const { app, BrowserWindow, ipcMain, nativeTheme, Menu, shell } = require('electron');
const path = require('path');
const fs = require('fs');
// Data file path
const dataPath = path.join(app.getPath('userData'), 'musevault-data.json');
function loadData() {
try {
if (fs.existsSync(dataPath)) {
return JSON.parse(fs.readFileSync(dataPath, 'utf-8'));
}
} catch (e) {
console.error('Failed to load data:', e);
}
return [];
}
function saveData(entries) {
try {
fs.writeFileSync(dataPath, JSON.stringify(entries, null, 2), 'utf-8');
return true;
} catch (e) {
console.error('Failed to save data:', e);
return false;
}
}
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1100,
height: 750,
minWidth: 680,
minHeight: 500,
titleBarStyle: 'hiddenInset',
trafficLightPosition: { x: 18, y: 18 },
vibrancy: 'under-window',
visualEffectState: 'active',
backgroundColor: '#00000000',
transparent: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: true,
nodeIntegration: false,
},
show: false,
});
mainWindow.loadFile('index.html');
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
// Build menu
const template = [
{
label: app.name,
submenu: [
{ role: 'about' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' },
],
},
{
label: 'File',
submenu: [
{
label: 'New Prompt',
accelerator: 'CmdOrCtrl+N',
click: () => mainWindow.webContents.send('menu-action', 'new-prompt'),
},
{
label: 'New Lyrics',
accelerator: 'CmdOrCtrl+Shift+N',
click: () => mainWindow.webContents.send('menu-action', 'new-lyrics'),
},
{ type: 'separator' },
{
label: 'Export Data...',
accelerator: 'CmdOrCtrl+E',
click: () => mainWindow.webContents.send('menu-action', 'export'),
},
{
label: 'Import Data...',
accelerator: 'CmdOrCtrl+I',
click: () => mainWindow.webContents.send('menu-action', 'import'),
},
],
},
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'selectAll' },
],
},
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forceReload' },
{ type: 'separator' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ role: 'resetZoom' },
{ type: 'separator' },
{ role: 'togglefullscreen' },
],
},
{
label: 'Window',
submenu: [
{ role: 'minimize' },
{ role: 'zoom' },
{ type: 'separator' },
{ role: 'front' },
],
},
];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
}
// IPC handlers for data persistence
ipcMain.handle('load-entries', () => loadData());
ipcMain.handle('save-entries', (_, entries) => saveData(entries));
ipcMain.handle('get-data-path', () => dataPath);
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
app.quit();
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});