~dricottone/noticable

ref: 4d60328797c769865abfe3bc739d0e82c1f233f7 noticable/main.js -rw-r--r-- 1.2 KiB
4d603287Dominic Ricottone functional file reading 3 years ago
                                                                                
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
const { app, BrowserWindow } = require('electron');
const shortcut = require('electron-localshortcut');
const path = require('path');

let win;
const createWindow = () => {
  win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      contextIsolation: true,
      nodeIntegration: false,
      preload: path.join(__dirname, 'preload.js')
    }
  });

  win.loadFile(path.join(__dirname, 'index.html'));

  shortcut.register(win, 'CmdOrCtrl+S', () => {
    console.log("[main] triggering 'request-render-markdown'...")
    win.webContents.send('request-render-markdown', '');
  });
  shortcut.register(win, 'CmdOrCtrl+E', () => {
    console.log("[main] triggering 'request-focus-editor'...")
    win.webContents.send('request-focus-editor', '');
  });

  win.on('closed', () => {
    win = null;
  });
};

// initialize
app.on('ready', createWindow);

// macOS convention is to keep process alive (accessible via the dock) until
// explicitly quit; must handle re-initialization
app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  if (win === null) {
    createWindow();
  }
});