wojtkowiak / meteor-desktop

Build a Meteor's desktop client with hot code push.
MIT License
448 stars 81 forks source link

meteor desktop 2.2.5 + single instance on + electron 4+ fails to start #274

Open dorian-coygo opened 4 years ago

dorian-coygo commented 4 years ago

Setup: package.json

meteor-desktop: 2.2.5
electron: 4.0.0

.desktop/settings

singleInstance: true

command:

meteor npm run desktop -- run 127.0.0.1:3000

Expected result: The app to successfully build

Current result:

debug: [main] skeleton version 2.2.5
verbose: [main] setting single instance mode
App threw an error during load
TypeError: app.makeSingleInstance is not a function
    at App.applySingleInstance (/Users/dkersch/Development/coygo/webapp/.meteor/desktop-build/app/app.js:131:42)
    at new App (/Users/dkersch/Development/coygo/webapp/.meteor/desktop-build/app/app.js:63:14)
    at Object.<anonymous> (/Users/dkersch/Development/coygo/webapp/.meteor/desktop-build/app/app.js:731:25)
    at Module._compile (internal/modules/cjs/loader.js:786:30)
    at Object.extWrap (/Users/dkersch/Development/coygo/webapp/.meteor/desktop-build/node_modules/reify/node/compile-hook.js:53:7)
    at Object.extManager (/Users/dkersch/Development/coygo/webapp/.meteor/desktop-build/node_modules/reify/node/compile-hook.js:19:12)
    at Object.manager [as .js] (/Users/dkersch/Development/coygo/webapp/.meteor/desktop-build/node_modules/reify/node/wrapper.js:108:20)
    at Module.load (internal/modules/cjs/loader.js:645:32)
    at Function.Module._load (internal/modules/cjs/loader.js:560:12)
    at Module.require (internal/modules/cjs/loader.js:685:19)

Looks like makeSingleInstance() was deprecated in 4.0

Issue in skeleton code.

Potential workaround: singleInstance: false

Potential fix for everyone (briefly tested on my fork):

if (semver.lt(process.versions.electron, '4.0.0')) { //https://www.electronjs.org/docs/all#appmakesingleinstance
    const isSecondInstance = app.makeSingleInstance(() => {
        // Someone tried to run a second instance, we should focus our window.
        if (this.window) {
            if (this.window.isMinimized()) {
                this.window.restore();
            }
            this.window.focus();
        }
    });
} else {
    app.requestSingleInstanceLock()
    const isSecondInstance = app.on('second-instance', () => {
        // Someone tried to run a second instance, we should focus our window.
        if (this.window) {
            if (this.window.isMinimized()) {
                this.window.restore();
            }
            this.window.focus();
        }
            this.l.warn('current instance was terminated because another instance is running');
            app.quit();
    });
}