Skip to content

Commit

Permalink
Fix: Open with OpenComic not working in macOS and some fixes in Windo…
Browse files Browse the repository at this point in the history
…ws and Linux
  • Loading branch information
ollm committed Dec 5, 2023
1 parent 1b2b638 commit ea90063
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Reading shortcuts remain active when going back to recently opened [`716c10b`](https://github.com/ollm/OpenComic/commit/716c10b3a6b3ec17352952bba6a19b3b1a4dd66a)
- Some errors on go back before comic load [`99fb29d`](https://github.com/ollm/OpenComic/commit/99fb29dab7b07a94883199665167a1301774f4e8)
- Blank page keep white color in dark theme [`8d1a5b7`](https://github.com/ollm/OpenComic/commit/8d1a5b741855fd0bae6a7efd9579c7ddecbfd3d1)
- Open with OpenComic not working in macOS and some fixes in Windows and Linux

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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "opencomic",
"productName": "OpenComic",
"version": "1.0.0-beta.6",
"version": "1.0.0",
"main": "scripts/main.js",
"type": "commonjs",
"keywords": [
Expand Down
28 changes: 24 additions & 4 deletions scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {app, ipcMain, BrowserWindow, Menu, nativeImage} = require('electron');
const fs = require('fs');
const path = require('path');
const url = require('url');
const windowStateKeeper = require('electron-window-state');
Expand All @@ -15,12 +16,31 @@ process.traceProcessWarnings = true;
function createWindow() {
// Create the browser window.

var mainWindowState = windowStateKeeper({
let gotSingleInstanceLock = app.requestSingleInstanceLock();
if(!gotSingleInstanceLock)
{
let toOpenFile = false;

for(let i = 1, len = process.argv.length; i < len; i++)
{
let arg = process.argv[i];

if(arg && ['scripts/main.js', '.'].indexOf(arg) == -1 && !/^--/.test(arg) && fs.existsSync(arg))
{
toOpenFile = arg;
break;
}
}

if(toOpenFile) app.quit();
}

let mainWindowState = windowStateKeeper({
defaultWidth: 1100,
defaultHeight: 640
});

var image = nativeImage.createFromPath(path.join(__dirname, '../images/logo.png'));
let image = nativeImage.createFromPath(path.join(__dirname, '../images/logo.png'));

win = new BrowserWindow({
show: false,
Expand Down Expand Up @@ -53,7 +73,7 @@ function createWindow() {

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

var menuTemplate = [
let menuTemplate = [
{
label: '...',
submenu: [
Expand All @@ -64,7 +84,7 @@ function createWindow() {
}
];

var menu = Menu.buildFromTemplate(menuTemplate);
let menu = Menu.buildFromTemplate(menuTemplate);
win.setMenu(menu);

win.removeMenu();
Expand Down
71 changes: 68 additions & 3 deletions scripts/opencomic.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,38 @@ require('jquery-bez');

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

var testVar = 'test';
var toOpenFile = false, windowHasLoaded = false;

electronRemote.app.on('open-file', function(event, path) {

if(windowHasLoaded)
openComic(path, true);
else
toOpenFile = path;

});

electronRemote.app.on('second-instance', function(event, argv) {

if(electronRemote.app.hasSingleInstanceLock())
{
let win = electronRemote.getCurrentWindow();
if (win.isMinimized()) win.restore();
win.focus();

for(let i = 1, len = argv.length; i < len; i++)
{
let arg = argv[i];

if(arg && !inArray(arg, ['--no-sandbox', 'scripts/main.js', '.']) && !/^--/.test(arg) && fs.existsSync(arg))
{
openComic(arg, true);
break;
}
}
}

});

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

if(electronRemote.process.argv && electronRemote.process.argv[1] && !inArray(electronRemote.process.argv[1], ['--no-sandbox', 'scripts/main.js', '.']) && fs.existsSync(electronRemote.process.argv[1]))
if(!toOpenFile)
{
for(let i = 1, len = electronRemote.process.argv.length; i < len; i++)
{
let arg = electronRemote.process.argv[i];

if(arg && !inArray(arg, ['scripts/main.js', '.']) && !/^--/.test(arg) && fs.existsSync(arg))
{
toOpenFile = arg;
break;
}
}
}

if(toOpenFile && fs.existsSync(toOpenFile))
{
openComic(electronRemote.process.argv[1], false);
openComic(toOpenFile, false);
}
else
{
Expand Down Expand Up @@ -415,6 +460,8 @@ async function startApp()

});

windowHasLoaded = true;

}

var ShoSho = false;
Expand Down Expand Up @@ -1082,6 +1129,24 @@ function openComic(filePath, animation = true)
else
dom.loadIndexPage(animation, path, false, false, mainPath);
}
else
{
if(!windowHasLoaded)
dom.loadIndexPage(false);

events.snackbar({
key: 'unsupportedFile',
text: language.global.unsupportedFile,
duration: 6,
update: true,
buttons: [
{
text: language.buttons.dismiss,
function: 'events.closeSnackbar();',
},
],
});
}
}

function addComic(folders = false)
Expand Down

0 comments on commit ea90063

Please sign in to comment.