Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

fix(startup): enforce single-instance app lock to prevent duplicate menus

webadderall2599ccbf9bc5
diff --git a/electron/main.ts b/electron/main.ts
index d3ef0ed9..adc010ea 100644
--- a/electron/main.ts
+++ b/electron/main.ts
@@ -49,6 +49,11 @@ let tray: Tray | null = null
let selectedSourceName = ''
let editorHasUnsavedChanges = false
let isForceClosing = false
+const hasSingleInstanceLock = app.requestSingleInstanceLock()
+
+if (!hasSingleInstanceLock) {
+ app.quit()
+}
function closeEditorWindowBypassingUnsavedPrompt(window: BrowserWindow | null) {
if (!window || window.isDestroyed()) {
@@ -72,6 +77,20 @@ function createWindow() {
mainWindow = createHudOverlayWindow()
}
+function focusOrCreateMainWindow() {
+ if (BrowserWindow.getAllWindows().length === 0) {
+ createWindow()
+ return
+ }
+
+ if (mainWindow && !mainWindow.isDestroyed()) {
+ if (mainWindow.isMinimized()) mainWindow.restore()
+ mainWindow.show()
+ mainWindow.focus()
+ mainWindow.moveTop()
+ }
+}
+
function isEditorWindow(window: BrowserWindow) {
return window.webContents.getURL().includes('windowType=editor')
}
@@ -321,14 +340,11 @@ app.on('window-all-closed', () => {
app.on('activate', () => {
// On OS X 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 (BrowserWindow.getAllWindows().length === 0) {
- createWindow()
- } else if (mainWindow && !mainWindow.isDestroyed()) {
- if (mainWindow.isMinimized()) mainWindow.restore();
- mainWindow.show();
- mainWindow.focus();
- mainWindow.moveTop();
- }
+ focusOrCreateMainWindow()
+})
+
+app.on('second-instance', () => {
+ focusOrCreateMainWindow()
})