showing results for - "electron sample question"
Ivanna
07 Jul 2017
1'use strict';
2const path = require('path');
3const { app, BrowserWindow, Menu, globalShortcut} = require('electron');
4const unhandled = require('electron-unhandled');
5const debug = require('electron-debug');
6const {is} = require('electron-util');
7
8unhandled();
9debug();
10contextMenu();
11
12// Note: Must match `build.appId` in package.json
13app.setAppUserModelId('com.pixzeldigital.attrfidqrcode');
14
15// Prevent window from being garbage collected
16let mainWindow;
17
18const createMainWindow = async () => {
19
20    const win = new BrowserWindow({
21        title: app.name,
22        show: false,
23        width: 1024,
24        height: 768,
25        frame: false
26    });
27
28    win.on('ready-to-show', () => {
29        win.maximize();
30        win.show();
31    });
32
33    win.on('closed', () => {
34        // Dereference the window
35        // For multiple windows store them in an array
36        mainWindow = undefined;
37    });
38
39    await win.loadFile(path.join(__dirname, 'vue/dist/index.html'));
40
41    return win;
42};
43
44// Prevent multiple instances of the app
45if (!app.requestSingleInstanceLock()) {
46    app.quit();
47}
48
49app.on('second-instance', () => {
50    if (mainWindow) {
51        if (mainWindow.isMinimized()) {
52            mainWindow.restore();
53        }
54
55        mainWindow.show();
56    }
57});
58
59app.on('window-all-closed', () => {
60    if (!is.macos) {
61        app.quit();
62    }
63});
64
65app.on('activate', async () => {
66    if (!mainWindow) {
67        mainWindow = await createMainWindow();
68    }
69});
70
71app.on('ready', () => {
72    // Register a shortcut listener for Ctrl + Shift + I
73    globalShortcut.register('Control+Shift+I', () => {
74        // When the user presses Ctrl + Shift + I, this function will get called
75        // You can modify this function to do other things, but if you just want
76        // to disable the shortcut, you can just return false
77        return false;
78    });
79});
80
81(async () => {
82    await app.whenReady();
83    Menu.setApplicationMenu(null);
84    mainWindow = await createMainWindow();
85})();
86