From 610a233f8a6535bf90ab9b4a92ebbe5d63d984ee Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Tue, 31 Mar 2020 19:59:05 +0800 Subject: [PATCH] try to fix #286 --- .github/workflows/build.yml | 4 ++-- public/electron.js | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 36d1a211..2bd15049 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,8 +8,8 @@ jobs: strategy: matrix: -# os: [macos-latest, ubuntu-latest, windows-latest] - os: [windows-latest] + os: [macos-latest, ubuntu-latest, windows-latest] +# os: [windows-latest] steps: - name: Check out Git repository diff --git a/public/electron.js b/public/electron.js index eaff4fa8..3266fdf9 100644 --- a/public/electron.js +++ b/public/electron.js @@ -1,6 +1,6 @@ const electron = require('electron'); // eslint-disable-line const isDev = require('electron-is-dev'); -const path = require('path'); +const { join } = require('path'); const menu = require('./menu'); @@ -16,6 +16,11 @@ app.name = 'LosslessCut'; let mainWindow; let askBeforeClose = false; +let rendererReady = false; + +function openFile(path) { + mainWindow.webContents.send('file-opened', [path]); +} function createWindow() { mainWindow = new BrowserWindow({ @@ -27,7 +32,7 @@ function createWindow() { }, }); - mainWindow.loadURL(isDev ? 'http://localhost:3001' : `file://${path.join(__dirname, '../build/index.html')}`); + mainWindow.loadURL(isDev ? 'http://localhost:3001' : `file://${join(__dirname, '../build/index.html')}`); if (isDev) { const { default: installExtension, REACT_DEVELOPER_TOOLS } = require('electron-devtools-installer'); // eslint-disable-line global-require,import/no-extraneous-dependencies @@ -92,12 +97,21 @@ app.on('activate', () => { } }); +let openFileInitial; + electron.ipcMain.on('renderer-ready', () => { + rendererReady = true; if (!isDev) { const fileToOpen = process.argv[1]; // https://github.com/electron/electron/issues/3657 - if (fileToOpen && !fileToOpen.startsWith('-psn_')) mainWindow.webContents.send('file-opened', [fileToOpen]); + if (fileToOpen && !fileToOpen.startsWith('-psn_')) openFile(fileToOpen); } + if (openFileInitial) openFile(openFileInitial); +}); + +app.on('open-file', (event, path) => { + if (rendererReady) openFile(path); + else openFileInitial = path; }); electron.ipcMain.on('setAskBeforeClose', (e, val) => {