forked from kevinfiol/rss-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
111 lines (99 loc) · 2.64 KB
/
main.js
File metadata and controls
111 lines (99 loc) · 2.64 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
const { app, BrowserWindow, shell } = require('electron');
const path = require('path');
const fs = require('fs');
const { spawn } = require('child_process');
// Function to run the build script
function runBuildScript() {
return new Promise((resolve, reject) => {
console.log('Building RSS feeds...');
const buildProcess = spawn('npm', ['run', 'build'], {
stdio: 'inherit'
});
buildProcess.on('close', (code) => {
if (code === 0) {
console.log('Build completed successfully');
resolve();
} else {
console.error(`Build process exited with code ${code}`);
reject(new Error(`Build failed with code ${code}`));
}
});
});
}
// Check if output/index.html exists, if not run the build
async function ensureOutputExists() {
const indexPath = path.join(__dirname, 'output', 'index.html');
if (!fs.existsSync(indexPath)) {
await runBuildScript();
}
}
function createWindow() {
const win = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: false,
contextIsolation: true
}
});
// Set window title to "fukuro"
win.setTitle("fukuro");
// Load the static site (built into "output/index.html")
win.loadFile(path.join(__dirname, 'output/index.html'));
// Open external links in the default browser
win.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: 'deny' };
});
// Add menu with refresh option
const { Menu } = require('electron');
const menu = Menu.buildFromTemplate([
{
label: 'File',
submenu: [
{
label: 'Refresh Feeds',
accelerator: 'CmdOrCtrl+R',
click: async () => {
try {
await runBuildScript();
win.reload();
} catch (error) {
console.error('Failed to refresh feeds:', error);
}
}
},
{ type: 'separator' },
{ role: 'quit' }
]
},
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'toggleDevTools' },
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
]
}
]);
Menu.setApplicationMenu(menu);
}
app.whenReady().then(async () => {
await ensureOutputExists();
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});