📜  电子示例问题 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:09.527000             🧑  作者: Mango

代码示例1
'use strict';
const path = require('path');
const { app, BrowserWindow, Menu, globalShortcut} = require('electron');
const unhandled = require('electron-unhandled');
const debug = require('electron-debug');
const {is} = require('electron-util');

unhandled();
debug();
contextMenu();

// Note: Must match `build.appId` in package.json
app.setAppUserModelId('com.pixzeldigital.attrfidqrcode');

// Prevent window from being garbage collected
let mainWindow;

const createMainWindow = async () => {

    const win = new BrowserWindow({
        title: app.name,
        show: false,
        width: 1024,
        height: 768,
        frame: false
    });

    win.on('ready-to-show', () => {
        win.maximize();
        win.show();
    });

    win.on('closed', () => {
        // Dereference the window
        // For multiple windows store them in an array
        mainWindow = undefined;
    });

    await win.loadFile(path.join(__dirname, 'vue/dist/index.html'));

    return win;
};

// Prevent multiple instances of the app
if (!app.requestSingleInstanceLock()) {
    app.quit();
}

app.on('second-instance', () => {
    if (mainWindow) {
        if (mainWindow.isMinimized()) {
            mainWindow.restore();
        }

        mainWindow.show();
    }
});

app.on('window-all-closed', () => {
    if (!is.macos) {
        app.quit();
    }
});

app.on('activate', async () => {
    if (!mainWindow) {
        mainWindow = await createMainWindow();
    }
});

app.on('ready', () => {
    // Register a shortcut listener for Ctrl + Shift + I
    globalShortcut.register('Control+Shift+I', () => {
        // When the user presses Ctrl + Shift + I, this function will get called
        // You can modify this function to do other things, but if you just want
        // to disable the shortcut, you can just return false
        return false;
    });
});

(async () => {
    await app.whenReady();
    Menu.setApplicationMenu(null);
    mainWindow = await createMainWindow();
})();