本文整理汇总了TypeScript中electron.app.once方法的典型用法代码示例。如果您正苦于以下问题:TypeScript app.once方法的具体用法?TypeScript app.once怎么用?TypeScript app.once使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类electron.app
的用法示例。
在下文中一共展示了app.once方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: init
export async function init() {
log('Waiting for app to be ready');
app.once('ready', async () => {
log('App is ready, waiting for settings to initialize');
await Settings.init();
log('Settings initialized');
await Setup.init();
log('Done setupping, initializing autolauncher');
await AutoLauncher.init();
log('Initializing tray icon');
SystemTray.init();
log('Done initializing everything');
if (Refs.DEBUG || !(await Settings.get('launchOnBoot'))) {
//Not launch on boot, that means that this launch should start the app
log('Launching main window');
launch(true);
} else {
log('Not launching main window');
}
app.on('window-all-closed', async () => {
if (Refs.DEBUG || !(await Settings.get('launchOnBoot'))) {
//Not launch on boot, so close when done
app.quit();
}
});
});
}
示例2: makeDefaultConfig
fs.readFile(file, 'utf8', (err, json) => {
if (err) {
log.info('Configuration file was not found, will create:', file);
const onSaved = (saveErr: Error) => {
if (saveErr) {
log.error('Failed to write configuration file:', file, saveErr);
} else {
log.info('Configuration file was created at', file);
}
};
const default_config = makeDefaultConfig();
// Note:
// If calling writeFile() directly here, it tries to create config file before Electron
// runtime creates data directory. As the result, writeFile() would fail to create a file.
if (app.isReady()) {
fs.writeFile(file, JSON.stringify(default_config, null, 2), onSaved);
} else {
app.once('ready', () => fs.writeFile(file, JSON.stringify(default_config, null, 2), onSaved));
}
return resolve(default_config);
}
try {
const config = JSON.parse(json);
if (config.hot_key && config.hot_key.startsWith('mod+')) {
config.hot_key = `CmdOrCtrl+${config.hot_key.slice(4)}`;
}
log.debug('Configuration was loaded successfully', config);
resolve(config);
} catch (e) {
log.error('Error on loading JSON file, will load default configuration:', e.message);
resolve(makeDefaultConfig());
}
});
示例3: it
it('should emit browser-window-blur event when window is blured', (done) => {
app.once('browser-window-blur', (e, window) => {
expect(w.id).to.equal(window.id)
done()
})
w = new BrowserWindow({ show: false })
w.emit('blur')
})
示例4: handlePotentialProtocolLaunch
const handlePotentialProtocolLaunch = (url: string) => {
if (!app.isReady()) {
app.once('ready', () => handlePotentialProtocolLaunch(url));
return;
}
const parsed = nodeUrl.parse(url.replace(/\/$/, ''));
if (!parsed.pathname) return;
const pathParts = parsed.pathname.split('/');
if (pathParts.length <= 0 || pathParts.length > 2) return;
ipcMainManager.send(IpcEvents.LOAD_GIST_REQUEST, [parsed.pathname]);
};
示例5:
this.pendingQuitPromise = new TPromise<boolean>((c) => {
// Store as field to access it from a window cancellation
this.pendingQuitPromiseComplete = c;
app.once('will-quit', () => {
if (this.pendingQuitPromiseComplete) {
this.pendingQuitPromiseComplete(false /* no veto */);
delete this.pendingQuitPromiseComplete;
delete this.pendingQuitPromise;
}
});
app.quit();
});
示例6: start
export async function start(
getMainWindow: () => BrowserWindow,
messages: MessagesType,
logger: LoggerType
) {
logger.info('macos/start: starting checks...');
loggerForQuitHandler = logger;
app.once('quit', quitHandler);
setInterval(async () => {
try {
await checkDownloadAndInstall(getMainWindow, messages, logger);
} catch (error) {
logger.error('macos/start: error:', getPrintableError(error));
}
}, INTERVAL);
await checkDownloadAndInstall(getMainWindow, messages, logger);
}
示例7: function
win.setMenuBarVisibility(false);
}
win.once('closed', function() {
win = null;
});
win.loadURL(index_html);
if (process.env.NODE_ENV !== 'production' && is_run_from_npm_package_on_darwin) {
win.webContents.openDevTools({mode: 'detach'});
}
return win;
}
app.once('window-all-closed', () => app.quit());
app.on('open-url', (e: Event, u: string) => {
e.preventDefault();
shell.openExternal(u);
});
app.once(
'ready',
() => {
if (process.platform === 'darwin' && is_run_from_npm_package_on_darwin) {
// XXX:
// app.dock.setIcon() is not defined in github-electron.d.ts yet.
(app.dock as any).setIcon(join(__dirname, '..', 'resources', 'icon', 'nyaovim-logo.png'));
}
Promise.all([