DeskGap API Demo

Menu

Node.js script

const contextMenu = Menu.buildFromTemplate([{ label: '' }]);
contextMenu.popup(browserWindow);

            

dialog

showErrorBox

Node.js script

dialog.showErrorBox('', '');

            

showOpenDialogAsync


await dialog.showOpenDialogAsync(browserWindow, {
    properties: [  ]
})
            

showSaveDialogAsync


await dialog.showSaveDialogAsync(browserWindow, { })
            

Draggable Area

<div data-deskgap-drag>

Drag me to move the window.

<div data-deskgap-no-drag>Non-draggable area</div>

</div>

BrowserWindow

Events

Node.js script

browserWindow.on('blur', () => console.log('Not Focused'));
browserWindow.on('focus', () => console.log('Focused'));
            

Last Output:

Size & Position

Node.js script

browserWindow.setSize(, );
browserWindow.setPosition(, );
browserWindow.center();
            

titleBarStyle (macOS only)

Node.js script

browserWindow.setTitleBarStyle('');
            

Vibrancies (macOS only)

Node.js script

browserWindow.setVibrancies([


]);
            

Messages

Asynchronously sending messages between Node.js and UI.

Node.js script

messageNode.on('hello-to-node', (e, message) => {
    e.sender.send('hello-from-node', "Hello, " + message);
});
            
UI script

messageUI.on('hello-from-node', (e, message) => {
    console.log(message);
});
messageUI.send('hello-to-node', '');
            

asyncNode

Asynchronously calling Node.js from UI.

Access global values in Node.js

UI script

await deskgap.asyncNode.getGlobal('process').prop('').value();
            

Require Node.js CommonJS modules

UI script

const os = await deskgap.asyncNode.require('os');
await os.invoke('').value();
            

Access the current BrowserWindow object

UI script

await deskgap.asyncNode.getCurrentWindow().invoke('getPosition').value();