Skip to content

Commit 37c5d29

Browse files
authored
Fix: Opening OpenComic multiple times creates new instances instead of opening a new window
1 parent 96ede09 commit 37c5d29

3 files changed

Lines changed: 17 additions & 26 deletions

File tree

scripts/main.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,9 @@ function createWindow(options = {}) {
3737
let sendInitData = false;
3838

3939
let gotSingleInstanceLock = app.requestSingleInstanceLock();
40-
if(!gotSingleInstanceLock)
41-
{
42-
let _toOpenFile = false;
43-
44-
const len = args.length;
45-
const last = args[len - 1];
46-
47-
if(/^opencomic:\/\//.test(last))
48-
app.quit();
49-
50-
for(let i = 1; i < len; i++)
51-
{
52-
let arg = args[i];
5340

54-
if(arg && !['--no-sandbox', 'scripts/main.js', '.dist/main.js', '.', '--new-window'].includes(arg) && !/^--/.test(arg) && !/app\.asar/i.test(arg) && fs.existsSync(arg))
55-
{
56-
_toOpenFile = arg;
57-
break;
58-
}
59-
}
60-
61-
if(_toOpenFile && !newWindow) app.quit();
62-
}
41+
if(!gotSingleInstanceLock)
42+
app.quit();
6343

6444
let mainWindowState = windowStateKeeper({
6545
defaultWidth: 1100,

scripts/opencomic.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ electronRemote.app.on('second-instance', function(event, argv) {
171171
}
172172

173173
openComic(arg, true);
174-
break;
174+
return;
175175
}
176176
}
177177

178+
openEmptyNewWindow();
179+
178180
});
179181

180182
function registreOpenUrl()
@@ -351,6 +353,7 @@ electron.ipcRenderer.on('init-data', function(event, data) {
351353
});
352354

353355
let historyFromStartApp = false;
356+
let emptyNewWindow = false;
354357

355358
async function loadFromHistory()
356359
{
@@ -378,6 +381,7 @@ async function startApp()
378381

379382
const args = [...process.argv, ...electronRemote.process.argv];
380383

384+
emptyNewWindow = args.includes('--empty-new-window');
381385
let toOpenFileMainPath = getArgValue(args, '--main-path', false);
382386
toOpenFile = toOpenFile || getArgValue(args, '--path', false);
383387

@@ -415,7 +419,7 @@ async function startApp()
415419

416420
let lastReading = false;
417421

418-
if(config.startInContinueReading)
422+
if(config.startInContinueReading && !emptyNewWindow)
419423
{
420424
let readingProgress = relative.get('readingProgress');
421425
let highest = 0;
@@ -480,7 +484,7 @@ async function startApp()
480484
}
481485
}
482486

483-
if(!config.restoreTabsFromLastSession || !tabs?.tabs?.length || (tabs.tabs.length === 1 && !config.showAlwaysTabsBar))
487+
if(emptyNewWindow || !config.restoreTabsFromLastSession || !tabs?.tabs?.length || (tabs.tabs.length === 1 && !config.showAlwaysTabsBar))
484488
{
485489
if(lastReading && fs.existsSync(lastReading.mainPath))
486490
dom.openComic(false, lastReading.path, lastReading.mainPath);
@@ -582,6 +586,12 @@ async function openPathInNewWindow(path, mainPath = '', history = null, options
582586
return await openNewWindow(['--path='+path, '--new-window', '--window-x='+x, '--window-y='+y, '--window-width='+width, '--window-height='+height, '--main-path='+mainPath, '--init-history=true'], {initHistory: history, ...options});
583587
}
584588

589+
async function openEmptyNewWindow()
590+
{
591+
const {x, y, width, height} = electronRemote.getCurrentWindow().getBounds();
592+
return await openNewWindow(['--empty-new-window', '--new-window', '--window-x='+x, '--window-y='+y, '--window-width='+width, '--window-height='+height], {});
593+
}
594+
585595
function openPathInNewTab(path, mainPath = '')
586596
{
587597
const tabId = tabs.openPath(path, mainPath);

scripts/tabs/restore.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ declare const config: any;
77
declare const storage: any;
88
declare const template: any;
99
declare const handlebarsContext: any;
10+
declare const emptyNewWindow: boolean;
1011
/* eslint-enable @typescript-eslint/no-explicit-any */
1112

1213
interface TabSaved {
@@ -58,7 +59,7 @@ function save(throttle: boolean = true, updateActive: boolean = false): void {
5859

5960
function restore(openLastActiveTab: boolean = false): void {
6061

61-
if(!config.restoreTabsFromLastSession)
62+
if(!config.restoreTabsFromLastSession || emptyNewWindow)
6263
return;
6364

6465
const data = storage.get('tabs');

0 commit comments

Comments
 (0)