Skip to content
This repository was archived by the owner on Jul 2, 2023. It is now read-only.

Commit 155d6d7

Browse files
Merge pull request #36 from AndresMorelos/deep-link
Deep link: Will be used for web app
2 parents 5593451 + cc960f8 commit 155d6d7

File tree

4 files changed

+100
-44
lines changed

4 files changed

+100
-44
lines changed

app.js

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -497,50 +497,50 @@ function loadMainProcessFiles() {
497497
}
498498

499499
function initialize() {
500-
app.on('ready', () => {
501-
if (!app.isDefaultProtocolClient('invoncify')) {
502-
app.setAsDefaultProtocolClient('invoncify');
503-
}
504-
createTourWindow();
505-
createMainWindow();
506-
createPreviewWindow();
507-
setInitialValues();
508-
migrateData();
509-
if (isDev) addDevToolsExtension();
510-
addEventListeners();
511-
loadMainProcessFiles();
512-
// Show Tour Window
513-
const { showWindow } = require('./main/tour');
514-
showWindow('startup');
515-
});
516-
// Reactivate the app
517-
app.on('activate', () => {
518-
const { showWindow } = require('./main/tour');
519-
showWindow('activate');
520-
});
521-
// Close all windows before quit the app
522-
app.on('before-quit', () => {
523-
// Use condition in case quit sequence is initiated by autoUpdater
524-
// which will destroy all there windows already before emitting this event
525-
if (tourWindow !== null) tourWindow.destroy();
526-
if (mainWindow !== null) mainWindow.destroy();
527-
if (previewWindow !== null) previewWindow.destroy();
528-
});
529-
app.on('open-url', (event, url) => {
530-
ipcMain.send('open-dialog', {
531-
type: 'warning',
532-
title: 'Example',
533-
message: url,
500+
const gotTheLock = app.requestSingleInstanceLock();
501+
502+
if (!gotTheLock) {
503+
app.quit();
504+
} else {
505+
app.on('second-instance', (event, commandLine, workingDirectory) => {
506+
// Someone tried to run a second instance, we should focus our window.
507+
if (mainWindow) {
508+
if (mainWindow.isMinimized()) mainWindow.restore();
509+
mainWindow.focus();
510+
}
534511
});
535-
});
536512

537-
console.timeEnd('init');
513+
app.on('ready', () => {
514+
if (!app.isDefaultProtocolClient('invoncify')) {
515+
app.setAsDefaultProtocolClient('invoncify');
516+
}
517+
createTourWindow();
518+
createMainWindow();
519+
createPreviewWindow();
520+
setInitialValues();
521+
migrateData();
522+
if (isDev) addDevToolsExtension();
523+
addEventListeners();
524+
loadMainProcessFiles();
525+
// Show Tour Window
526+
const { showWindow } = require('./main/tour');
527+
showWindow('startup');
528+
});
529+
// Reactivate the app
530+
app.on('activate', () => {
531+
const { showWindow } = require('./main/tour');
532+
showWindow('activate');
533+
});
534+
// Close all windows before quit the app
535+
app.on('before-quit', () => {
536+
// Use condition in case quit sequence is initiated by autoUpdater
537+
// which will destroy all there windows already before emitting this event
538+
if (tourWindow !== null) tourWindow.destroy();
539+
if (mainWindow !== null) mainWindow.destroy();
540+
if (previewWindow !== null) previewWindow.destroy();
541+
});
542+
console.timeEnd('init');
543+
}
538544
}
539545

540-
// Auto-Start
541-
app.setLoginItemSettings({
542-
openAtLogin: true,
543-
enabled: true,
544-
});
545-
546-
initialize();
546+
initialize()

main/auto-start.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const { app } = require('electron');
2+
3+
// Auto-Start
4+
app.setLoginItemSettings({
5+
openAtLogin: true,
6+
enabled: true,
7+
});

main/deep-link.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const { app, BrowserWindow } = require('electron');
2+
const appConfig = require('electron-settings');
3+
4+
// Get mainWindow Object
5+
const mainWindowID = appConfig.getSync('mainWindowID');
6+
const mainWindow = BrowserWindow.fromId(mainWindowID);
7+
8+
app.on('open-url', (event, url) => {
9+
if (url.includes('invoncify://')) {
10+
let operation;
11+
const [protocol, request] = url.split('invoncify://');
12+
13+
if (request.includes('?')) {
14+
const [requestBase, queryParams] = request.split('?');
15+
16+
operation = requestBase;
17+
} else {
18+
operation = request;
19+
}
20+
21+
switch (operation) {
22+
case 'new': {
23+
mainWindow.webContents.send('menu-change-tab', 'form');
24+
break;
25+
}
26+
case 'invoices': {
27+
mainWindow.webContents.send('menu-change-tab', 'invoices');
28+
}
29+
case 'contacts': {
30+
mainWindow.webContents.send('menu-change-tab', 'contacts');
31+
break;
32+
}
33+
case 'statistics': {
34+
mainWindow.webContents.send('menu-change-tab', 'statistics');
35+
break;
36+
}
37+
case 'settings': {
38+
mainWindow.webContents.send('menu-change-tab', 'settings');
39+
break;
40+
}
41+
case 'preview': {
42+
// coming soon
43+
break;
44+
}
45+
default:
46+
break;
47+
}
48+
}
49+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "invoncify",
33
"homepage": "https://invoncify.andresmorelos.me",
44
"productName": "Invoncify",
5-
"version": "1.6.0",
5+
"version": "1.6.1",
66
"license": "GPL-3.0",
77
"description": "Flexible invoicing desktop app with beautiful & customizable templates",
88
"author": {

0 commit comments

Comments
 (0)