mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #6545 from rhysd/electron-makeSingleInstance
github-electron: Add makeSingleInstance() API to 'app' module
This commit is contained in:
@@ -35,6 +35,21 @@ app.on('window-all-closed', () => {
|
||||
app.quit();
|
||||
});
|
||||
|
||||
// Check single instance app
|
||||
var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
|
||||
// Someone tried to run a second instance, we should focus our window
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.focus();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (shouldQuit) {
|
||||
app.quit();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// This method will be called when Electron has done everything
|
||||
// initialization and ready for creating browser windows.
|
||||
app.on('ready', () => {
|
||||
|
||||
Vendored
+6
@@ -986,6 +986,12 @@ declare module GitHubElectron {
|
||||
setUserTasks(tasks: Task[]): void;
|
||||
dock: BrowserWindow;
|
||||
commandLine: CommandLine;
|
||||
/**
|
||||
* This method makes your application a Single Instance Application instead of allowing
|
||||
* multiple instances of your app to run, this will ensure that only a single instance
|
||||
* of your app is running, and other instances signal this instance and exit.
|
||||
*/
|
||||
makeSingleInstance(callback: (args: string[], workingDirectory: string) => boolean): boolean;
|
||||
}
|
||||
|
||||
interface CommandLine {
|
||||
|
||||
Reference in New Issue
Block a user