-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectron-main.js
More file actions
182 lines (169 loc) · 4.47 KB
/
Copy pathelectron-main.js
File metadata and controls
182 lines (169 loc) · 4.47 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
// Electron Main Process for Brutal Notes
// This creates a native Windows/Mac/Linux desktop app
const { app, BrowserWindow, Menu } = require('electron');
const path = require('path');
let mainWindow;
function createWindow() {
// Create the browser window
mainWindow = new BrowserWindow({
width: 1400,
height: 900,
minWidth: 800,
minHeight: 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
enableRemoteModule: false,
webSecurity: true
},
icon: path.join(__dirname, 'icons/icon-512x512.png'),
title: 'Brutal Notes',
backgroundColor: '#1D1D1B',
show: false, // Don't show until ready
autoHideMenuBar: false,
frame: true
});
// Load the index.html
mainWindow.loadFile('index.html');
// Show window when ready
mainWindow.once('ready-to-show', () => {
mainWindow.show();
});
// Open DevTools in development (comment out for production)
// mainWindow.webContents.openDevTools();
// Handle window closed
mainWindow.on('closed', function () {
mainWindow = null;
});
// Create application menu
const menuTemplate = [
{
label: 'File',
submenu: [
{
label: 'New Document',
accelerator: 'CmdOrCtrl+N',
click: () => {
mainWindow.webContents.send('new-document');
}
},
{
label: 'Save',
accelerator: 'CmdOrCtrl+S',
click: () => {
mainWindow.webContents.send('save-document');
}
},
{ type: 'separator' },
{
label: 'Exit',
accelerator: 'CmdOrCtrl+Q',
click: () => {
app.quit();
}
}
]
},
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'selectAll' }
]
},
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'toggleDevTools' },
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
},
{
label: 'Help',
submenu: [
{
label: 'About Brutal Notes',
click: () => {
const aboutWindow = new BrowserWindow({
width: 400,
height: 300,
resizable: false,
parent: mainWindow,
modal: true,
show: false,
webPreferences: {
nodeIntegration: false
}
});
aboutWindow.loadURL(`data:text/html,
<html>
<head>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
margin: 0;
padding: 40px;
text-align: center;
background: #EAE4DA;
}
h1 { color: #1D1D1B; font-size: 28px; margin: 20px 0 10px; }
p { color: #666; margin: 10px 0; }
.version { font-size: 14px; color: #999; }
</style>
</head>
<body>
<h1>📝 Brutal Notes</h1>
<p class="version">Version 1.0.0</p>
<p>Stop Taking Wimpy Notes</p>
<p style="margin-top: 40px;">Made with ❤️ by yeatz</p>
</body>
</html>
`);
aboutWindow.once('ready-to-show', () => {
aboutWindow.show();
});
}
}
]
}
];
const menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu);
}
// App ready event
app.whenReady().then(createWindow);
// Quit when all windows are closed (except on macOS)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
// Activate event (macOS)
app.on('activate', function () {
if (mainWindow === null) {
createWindow();
}
});
// Prevent multiple instances
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
app.quit();
} else {
app.on('second-instance', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}
});
}