-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
49 lines (43 loc) · 1.28 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
// main.js
require('dotenv').config();
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const notifier = require('node-notifier');
const { generateDailyQuote, generateRandomFact } = require('./utils/quoteGenerator');
function createWindow() {
const win = new BrowserWindow({
width: 900,
height: 700,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false,
contextIsolation: true
}
});
win.loadFile('index.html');
}
app.whenReady().then(() => {
createWindow();
// IPC channel: Generate Daily Quote (now returns an object with text and tag)
ipcMain.handle('get-daily-quote', async () => {
const quote = await generateDailyQuote();
// Pass the text property to the notifier so it gets a string
notifier.notify({
title: 'Daily Inspiration',
message: quote.text,
sound: true
});
return quote;
});
// IPC channel: Generate Random Fact
ipcMain.handle('get-random-fact', async () => {
const fact = await generateRandomFact();
return fact;
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});