本文整理汇总了TypeScript中electron.app.makeSingleInstance方法的典型用法代码示例。如果您正苦于以下问题:TypeScript app.makeSingleInstance方法的具体用法?TypeScript app.makeSingleInstance怎么用?TypeScript app.makeSingleInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类electron.app
的用法示例。
在下文中一共展示了app.makeSingleInstance方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
let onReady = () => {
if (!env.integrationTests) {
const shouldQuit = app.makeSingleInstance((argv, cwd) => {
// we only get inside this callback when another instance
// is launched - so this executes in the context of the main instance
store.dispatch(
actions.processUrlArguments({
args: argv,
})
);
store.dispatch(actions.focusWind({ wind: "root" }));
});
if (shouldQuit) {
app.exit(0);
return;
}
}
store.dispatch(
actions.processUrlArguments({
args: process.argv,
})
);
globalShortcut.register("Control+Alt+Backspace", function() {
store.dispatch(actions.forceCloseLastGame({}));
});
// Emitted when the application is activated. Various actions can trigger
// this event, such as launching the application for the first time,
// attempting to re-launch the application when it's already running, or
// clicking on the application's dock or taskbar icon.
app.on("activate", () => {
store.dispatch(actions.focusWind({ wind: "root" }));
});
app.on("before-quit", e => {
e.preventDefault();
store.dispatch(actions.quit({}));
});
store.dispatch(actions.preboot({}));
setInterval(() => {
try {
store.dispatch(actions.tick({}));
} catch (e) {
mainLogger.error(`While dispatching tick: ${e.stack}`);
}
}, 1 * 1000 /* every second */);
};
示例2: function
let onReady = () => {
if (!env.integrationTests) {
const shouldQuit = app.makeSingleInstance((argv, cwd) => {
// we only get inside this callback when another instance
// is launched - so this executes in the context of the main instance
store.dispatch(
actions.processUrlArguments({
args: argv,
})
);
store.dispatch(actions.focusWindow({ window: "root" }));
});
if (shouldQuit) {
app.exit(0);
return;
}
}
store.dispatch(
actions.processUrlArguments({
args: process.argv,
})
);
globalShortcut.register("Control+Alt+Backspace", function() {
store.dispatch(actions.forceCloseLastGame({}));
});
if (rt) {
rt.end();
}
store.dispatch(actions.preboot({}));
setInterval(() => {
try {
store.dispatch(actions.tick({}));
} catch (e) {
logger.error(`While dispatching tick: ${e.stack}`);
}
}, 1 * 1000 /* every second */);
};
示例3: configSingletonWindow
configSingletonWindow(win: Electron.BrowserWindow) {
if (this.loaded_config === null || !this.loaded_config.single_instance) {
return false;
}
return app.makeSingleInstance((argv, cwd) => {
if (win.isMinimized()) {
win.restore();
}
win.focus();
// Note: Omit Electron binary and NyaoVim directory
const args = argv.slice(2);
if (args.length !== 0) {
win.webContents.send('nyaovim:exec-commands', [
'cd ' + cwd,
'args ' + args.join(' '),
]);
}
return true;
});
}
示例4: onAppReady
import * as electron from "electron";
import * as i18n from "./shared/i18n";
import getUserData from "./getUserData";
import "./export";
let userDataPath: string;
let mainWindow: Electron.BrowserWindow;
let trayIcon: Electron.Tray;
let trayMenu: Electron.Menu;
const standaloneWindowsById: { [id: string]: Electron.BrowserWindow } = {};
let shouldQuit = electron.app.makeSingleInstance((args, workingDirectory) => {
restoreMainWindow();
return true;
});
if (shouldQuit) {
electron.app.quit();
process.exit(0);
}
electron.app.on("ready", onAppReady);
electron.app.on("activate", () => { restoreMainWindow(); });
electron.app.on("before-quit", () => { shouldQuit = true; });
electron.ipcMain.on("new-standalone-window", onNewStandaloneWindow);
function onAppReady() {
electron.Menu.setApplicationMenu(null);
getUserData((dataPathErr, dataPath, languageCode) => {
示例5: quitApp
}
// Signals that the app is quitting and quits the app. This is necessary because we override the
// window 'close' event to support minimizing to the system tray.
async function quitApp() {
isAppQuitting = true;
await stopVpn();
app.quit();
}
const isSecondInstance = app.makeSingleInstance((argv, workingDirectory) => {
interceptShadowsocksLink(argv);
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized() || !mainWindow.isVisible()) {
mainWindow.restore();
mainWindow.show();
}
mainWindow.focus();
}
});
if (isSecondInstance) {
console.log('another instance is running - exiting');
app.quit();
}
app.setAsDefaultProtocolClient('ss');
function interceptShadowsocksLink(argv: string[]) {
if (argv.length > 1) {
示例6: canAutoupdate
(function () {
if (platform() == "win32") {
if (require('electron-squirrel-startup')) process.exit(0);
}
var devMode:boolean = (process.argv || []).indexOf('--dev') !== -1;
let win:Electron.BrowserWindow = null;
const shouldQuit:boolean = app.makeSingleInstance(() => {
if(win) {
if (win.isMinimized()) {
win.restore();
}
win.focus();
}
});
if (shouldQuit) {
app.quit();
return;
}
function canAutoupdate():boolean {
return !devMode && platform() === "win32";
}
function isWindows():boolean {
return platform() === 'win32';
}
function isOSX():boolean {
return platform() === "darwin";
}
function setupAutoUpdater():void {
// Don't even attempt to write the auto update unless we are on a system that supports it.
// Which as of the time of this comment only is windows.
if (!canAutoupdate()) return;
autoUpdater.addListener("update-available", function () {
win.webContents.send("update-info", "UPDATE.AVAILABLE");
});
autoUpdater.addListener("update-downloaded", function () {
win.webContents.send("update-info", "UPDATE.DOWNLOADED");
});
autoUpdater.addListener("error", function (error:any) {
console.log(error);
win.webContents.send("update-error", error);
});
autoUpdater.addListener("checking-for-update", function () {
win.webContents.send("update-info", "UPDATE.CHECKING_FOR_UPDATE");
});
autoUpdater.addListener("update-not-available", function () {
win.webContents.send("update-info", "UPDATE.NOT_AVAILABLE");
});
var feedUrl:string = "";
if (platform() == "win32") {
feedUrl = "http://zlepper.dk:3215/update/win";
if (arch() == "x64") {
console.log("64x windows detected.");
feedUrl += "64"
} else {
feedUrl += "32"
}
}
feedUrl += "/" + app.getVersion();
// The feed url was not set for some reason, so we'll not attempt to get any update package.
if (feedUrl == "") {
return;
}
autoUpdater.setFeedURL(feedUrl);
autoUpdater.checkForUpdates();
}
function unpackBackend(filename:string, cb:any) {
if (devMode) return cb();
var asarFile: string;
if (!isWindows()) {
asarFile = join(__dirname, basename(filename));
console.log("Path to zipped backend file: " + asarFile);
} else {
asarFile = join("resources", "app.asar", filename);
}
var read = createReadStream(asarFile);
var write = createWriteStream(filename);
console.log("Copying backend outside .asar file");
read.on("close", function () {
console.log("Finished");
if (isWindows()) {
cb();
} else {
// Mark the file as executeable, so we can actually start it
console.log("Marking backend as executeable");
exec("chmod +x \"" + filename + "\"", (error, stdout, stderr) => {
console.log("Backend was marked as executeable");
if (error) {
//.........这里部分代码省略.........
示例7: require
let mainWindow: Electron.BrowserWindow;
let trayIcon: Electron.Tray;
let trayMenu: Electron.Menu;
/* tslint:disable */
const expectedElectronVersion = require(`${__dirname}/package.json`).superpowers.electron;
/* tslint:enable */
const electronVersion = (process.versions as any).electron as string;
if (electronVersion !== expectedElectronVersion) {
console.log(`WARNING: Running Electron v${electronVersion}, but expected v${expectedElectronVersion}.`);
}
if (electron.app.makeSingleInstance(restoreMainWindow)) { electron.app.exit(0); }
electron.app.on("ready", onAppReady);
electron.app.on("activate", () => { restoreMainWindow(); });
let isQuitting = false;
let isReadyToQuit = false;
electron.app.on("before-quit", (event) => {
if (!isQuitting) {
event.preventDefault();
startCleanExit();
return;
}
if (!isReadyToQuit) event.preventDefault();
});
示例8: BrowserWindow
import {app, BrowserWindow} from 'electron';
import * as path from 'path';
let win: Electron.BrowserWindow = null;
const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (win) {
if (win.isMinimized()) {
win.restore();
}
win.focus();
return false;
} else {
return true;
}
});
if (shouldQuit) {
app.quit();
} else {
app.on('ready', () => {
// win = new BrowserWindow({ width: 800, height: 600, show: false ,autoHideMenuBar: true});
win = new BrowserWindow();
win.setMenuBarVisibility(false);
win.webContents.openDevTools();
// win.setVisibleOnAllWorkspaces(false);
win.on('closed', () => {
win = null;
});
win.loadURL('file:///' + path.join(__dirname, '../pages/index.html'));
// win.show();
示例9: EditorServicesClient
// Dereference the window object
mainWindow = null;
});
// Start PowerShell Editor Services
editorServicesClient = new EditorServicesClient();
editorServicesClient.start(mainWindow.webContents);
}
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);
}
app.on('ready', createWindow);
app.on('window-all-closed', function()
示例10: registerProtocolForLinux
start: (config) => {
// Register protocol for linux (update .desktop and mimeapps.list files)
if (process.platform === "linux") {
registerProtocolForLinux();
}
// Protocol handler for darwin
app.setAsDefaultProtocolClient("rabix-composer");
app.on("open-url", function (event, url) {
openExternalFiles(url);
focusMainWindow();
});
// File handler for darwin
app.on("open-file", function (event, filePath) {
openExternalFiles(filePath);
focusMainWindow();
});
// Initial File handler for win32 and linux
if (process.platform === "win32" || process.platform === "linux") {
openExternalFiles(...getFilePathsFromArgs(process.argv.slice(1)));
}
// File/Protocol handler for win32 and linux
const runningInstanceExists = app.makeSingleInstance((argv) => {
// Someone tried to run a second instance, we should focus our window.
// Protocol handler for win32 and linux
// argv: An array of the second instanceâs (command line / deep linked) arguments
if (process.platform === "win32" || process.platform === "linux") {
// Keep only command line / deep linked arguments
openExternalFiles(...getFilePathsFromArgs(argv.slice(1)));
}
focusMainWindow();
});
// If there is already a running instance of Composer, shut down this new one and let the existing one handle incoming data
if (runningInstanceExists) {
app.quit();
return
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on("ready", () => start(config));
// Quit when all windows are closed.
app.on("window-all-closed", () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
// if (process.platform !== "darwin") {
// app.quit();
// }
app.quit();
});
// This is not needed unless we add functionality again of re-creating window from menu bar (macOS)
// app.on("activate", () => {
// // On macOS it's common to re-create a window in the App when the
// // dock icon is clicked and there are no other windows open.
// if (win === null) {
// start(config);
// }
// });
}