electron#HandlerDetails TypeScript Examples

The following examples show how to use electron#HandlerDetails. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: main.ts    From bluebubbles-server with Apache License 2.0 5 votes vote down vote up
createWindow = async () => {
    win = new BrowserWindow({
        title: "BlueBubbles Server",
        useContentSize: true,
        width: 1080,
        minWidth: 850,
        height: 750,
        minHeight: 600,
        webPreferences: {
            nodeIntegration: true, // Required in new electron version
            contextIsolation: false // Required or else we get a `global` is not defined error
        }
    });

    if (process.env.NODE_ENV === "development") {
        process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = "1"; // eslint-disable-line require-atomic-updates
        win.loadURL(`http://localhost:3000`);
    } else {
        win.loadURL(`file://${path.join(__dirname, "index.html")}`);
    }

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

    // Prevent the title from being changed from BlueBubbles
    win.on("page-title-updated", evt => {
        evt.preventDefault();
    });

    // Make links open in the browser
    win.webContents.setWindowOpenHandler((details: HandlerDetails) => {
        shell.openExternal(details.url);
        return { action: 'deny' };
    });

    // Hook onto when we load the UI
    win.webContents.on("dom-ready", async () => {
        win.webContents.send("config-update", Server().repo.config);
    });

    // Set the new window in the Server()
    Server(win);
}
Example #2
Source File: app.ts    From SideQuest with MIT License 5 votes vote down vote up
function createWindow() {
    appWindow = new AppWindow(config);
    mainWindow = appWindow.window;
    require('@electron/remote/main').enable(mainWindow.webContents);
    if (process.env.NODE_ENV === 'dev') {
        mainWindow.loadURL('http://localhost:4205');
        mainWindow.webContents.openDevTools();
    } else {
        mainWindow.loadFile('build/app/index.html');
    }
    mainWindow.on('closed', function() {
        mainWindow = undefined;
    });

    setupMenu();
    mainWindow.webContents.once('dom-ready', async _e => {
        parseOpenUrl(process.argv);
        autoUpdater.autoDownload = false;
        if (process.platform !== 'linux') autoUpdater.checkForUpdates();
    });

    protocol.registerBufferProtocol('beatsaver', (request, _callback) => {
        mainWindow.webContents.send(
            'open-url',
            'sidequest://bsaber/#https://beatsaver.com/api/download/key/' + request.url.replace('beatsaver://', '')
        );
    });

    protocol.registerStringProtocol('sidequest', (request, _callback) => {
        mainWindow.webContents.send('open-url', request.url);
    });
    mainWindow.webContents.on('did-fail-load', () => mainWindow.loadURL(mainWindow.webContents.getURL()));
    addWindowDownloadHandler(mainWindow);
    const handleOpenWindow: (details: HandlerDetails) => { action: 'allow' } | { action: 'deny' } = e => {
        if (!e.postBody) {
            try {
                const extUrl = new URL(e.url).host.toLowerCase();
                if (OPEN_IN_SYSTEM_BROWSER_DOMAINS.includes(extUrl)) {
                    shell.openExternal(e.url);
                    return { action: 'deny' };
                }
            } catch (e) {
                console.log('could not open url', e);
                return { action: 'allow' };
            }
        }
        return { action: 'allow' };
    };
    let handleWindow;
    handleWindow = (child: BrowserWindow) => {
        child.webContents.on('did-attach-webview', (z, wc) => {
            wc.setWindowOpenHandler(handleOpenWindow);
            wc.on('did-create-window', child => {
                handleWindow(child);
            });
        });

        child.webContents.setWindowOpenHandler(handleOpenWindow);
        child.webContents.on('did-create-window', child => {
            console.log('did create window fired');
            handleWindow(child);
        });
    };
    handleWindow(mainWindow);
    mainWindow.webContents.session.setUserAgent(mainWindow.webContents.session.getUserAgent() + ' SQ/' + app.getVersion());
}