Skip to content

Commit ea90063

Browse files
committed
Fix: Open with OpenComic not working in macOS and some fixes in Windows and Linux
1 parent 1b2b638 commit ea90063

File tree

4 files changed

+94
-8
lines changed

4 files changed

+94
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1717
- Reading shortcuts remain active when going back to recently opened [`716c10b`](https://github.com/ollm/OpenComic/commit/716c10b3a6b3ec17352952bba6a19b3b1a4dd66a)
1818
- Some errors on go back before comic load [`99fb29d`](https://github.com/ollm/OpenComic/commit/99fb29dab7b07a94883199665167a1301774f4e8)
1919
- Blank page keep white color in dark theme [`8d1a5b7`](https://github.com/ollm/OpenComic/commit/8d1a5b741855fd0bae6a7efd9579c7ddecbfd3d1)
20+
- Open with OpenComic not working in macOS and some fixes in Windows and Linux
2021

2122
## [v1.0.0-beta.5](https://github.com/ollm/OpenComic/releases/tag/v1.0.0-beta.5) (24-11-2023)
2223

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "opencomic",
33
"productName": "OpenComic",
4-
"version": "1.0.0-beta.6",
4+
"version": "1.0.0",
55
"main": "scripts/main.js",
66
"type": "commonjs",
77
"keywords": [

scripts/main.js

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const {app, ipcMain, BrowserWindow, Menu, nativeImage} = require('electron');
2+
const fs = require('fs');
23
const path = require('path');
34
const url = require('url');
45
const windowStateKeeper = require('electron-window-state');
@@ -15,12 +16,31 @@ process.traceProcessWarnings = true;
1516
function createWindow() {
1617
// Create the browser window.
1718

18-
var mainWindowState = windowStateKeeper({
19+
let gotSingleInstanceLock = app.requestSingleInstanceLock();
20+
if(!gotSingleInstanceLock)
21+
{
22+
let toOpenFile = false;
23+
24+
for(let i = 1, len = process.argv.length; i < len; i++)
25+
{
26+
let arg = process.argv[i];
27+
28+
if(arg && ['scripts/main.js', '.'].indexOf(arg) == -1 && !/^--/.test(arg) && fs.existsSync(arg))
29+
{
30+
toOpenFile = arg;
31+
break;
32+
}
33+
}
34+
35+
if(toOpenFile) app.quit();
36+
}
37+
38+
let mainWindowState = windowStateKeeper({
1939
defaultWidth: 1100,
2040
defaultHeight: 640
2141
});
2242

23-
var image = nativeImage.createFromPath(path.join(__dirname, '../images/logo.png'));
43+
let image = nativeImage.createFromPath(path.join(__dirname, '../images/logo.png'));
2444

2545
win = new BrowserWindow({
2646
show: false,
@@ -53,7 +73,7 @@ function createWindow() {
5373

5474
require("@electron/remote/main").enable(win.webContents)
5575

56-
var menuTemplate = [
76+
let menuTemplate = [
5777
{
5878
label: '...',
5979
submenu: [
@@ -64,7 +84,7 @@ function createWindow() {
6484
}
6585
];
6686

67-
var menu = Menu.buildFromTemplate(menuTemplate);
87+
let menu = Menu.buildFromTemplate(menuTemplate);
6888
win.setMenu(menu);
6989

7090
win.removeMenu();

scripts/opencomic.js

+68-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,38 @@ require('jquery-bez');
8989

9090
//console.timeEnd('Require time 1');
9191

92-
var testVar = 'test';
92+
var toOpenFile = false, windowHasLoaded = false;
93+
94+
electronRemote.app.on('open-file', function(event, path) {
95+
96+
if(windowHasLoaded)
97+
openComic(path, true);
98+
else
99+
toOpenFile = path;
100+
101+
});
102+
103+
electronRemote.app.on('second-instance', function(event, argv) {
104+
105+
if(electronRemote.app.hasSingleInstanceLock())
106+
{
107+
let win = electronRemote.getCurrentWindow();
108+
if (win.isMinimized()) win.restore();
109+
win.focus();
110+
111+
for(let i = 1, len = argv.length; i < len; i++)
112+
{
113+
let arg = argv[i];
114+
115+
if(arg && !inArray(arg, ['--no-sandbox', 'scripts/main.js', '.']) && !/^--/.test(arg) && fs.existsSync(arg))
116+
{
117+
openComic(arg, true);
118+
break;
119+
}
120+
}
121+
}
122+
123+
});
93124

94125
var handlebarsContext = {};
95126
var language = {};
@@ -313,9 +344,23 @@ async function startApp()
313344
template.loadContentLeft('index.content.left.html', false);
314345
template.loadGlobalElement('index.elements.menus.html', 'menus');
315346

316-
if(electronRemote.process.argv && electronRemote.process.argv[1] && !inArray(electronRemote.process.argv[1], ['--no-sandbox', 'scripts/main.js', '.']) && fs.existsSync(electronRemote.process.argv[1]))
347+
if(!toOpenFile)
348+
{
349+
for(let i = 1, len = electronRemote.process.argv.length; i < len; i++)
350+
{
351+
let arg = electronRemote.process.argv[i];
352+
353+
if(arg && !inArray(arg, ['scripts/main.js', '.']) && !/^--/.test(arg) && fs.existsSync(arg))
354+
{
355+
toOpenFile = arg;
356+
break;
357+
}
358+
}
359+
}
360+
361+
if(toOpenFile && fs.existsSync(toOpenFile))
317362
{
318-
openComic(electronRemote.process.argv[1], false);
363+
openComic(toOpenFile, false);
319364
}
320365
else
321366
{
@@ -415,6 +460,8 @@ async function startApp()
415460

416461
});
417462

463+
windowHasLoaded = true;
464+
418465
}
419466

420467
var ShoSho = false;
@@ -1082,6 +1129,24 @@ function openComic(filePath, animation = true)
10821129
else
10831130
dom.loadIndexPage(animation, path, false, false, mainPath);
10841131
}
1132+
else
1133+
{
1134+
if(!windowHasLoaded)
1135+
dom.loadIndexPage(false);
1136+
1137+
events.snackbar({
1138+
key: 'unsupportedFile',
1139+
text: language.global.unsupportedFile,
1140+
duration: 6,
1141+
update: true,
1142+
buttons: [
1143+
{
1144+
text: language.buttons.dismiss,
1145+
function: 'events.closeSnackbar();',
1146+
},
1147+
],
1148+
});
1149+
}
10851150
}
10861151

10871152
function addComic(folders = false)

0 commit comments

Comments
 (0)