~dricottone/noticable

ref: 69444f9aa63311a90c5f89338a8bd2d52c6db7d4 noticable/main.js -rw-r--r-- 1.1 KiB
69444f9aDominic Ricottone reorganized js 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
const { app, BrowserWindow } = require("electron");
const shortcut = require("electron-localshortcut");
const path = require("path");

// initialize renderer
let win;
function 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-focus-editor'...");
    win.webContents.send("request-focus-editor", "");
  });
  shortcut.register(win, "CmdOrCtrl+E", () => {
    console.log("[main] triggering 'request-render-markdown'...");
    win.webContents.send("request-render-markdown", "");
  });
  win.on("closed", () => {
    win = null;
  });
};
app.on("ready", createWindow);

// macOS best practices
app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit();
  }
});
app.on("activate", () => {
  if (win === null) {
    createWindow();
  }
});