Git Product home page Git Product logo

Comments (31)

nickav avatar nickav commented on July 19, 2024 14

For anyone running into this issue for Electron apps, manually setting path to the outermost application path works. Here's my temporary workaround (tested on 10.9 and 10.11):

var appPath = app.getPath('exe').split('.app/Content')[0] + '.app';
appLauncher = new AutoLaunch({
  name: app.getName(),
  path: appPath,
});

from node-auto-launch.

guerrerocarlos avatar guerrerocarlos commented on July 19, 2024 6

Meanwhile, I pushed a patched version of this module to npm: auto-update-patched

npm install auto-launch-patched

var AutoLaunch = require('auto-launch-patched');

So it can be used instead, while #34 is merged into auto-launch.

from node-auto-launch.

djpereira avatar djpereira commented on July 19, 2024 2

I have the same experience on OSX 10.11.4 and I am using electron with electron-builder.
"electron-builder": "~3.25.0",
"electron-prebuilt": "~1.1.3",

I noticed that in OSX it is creating a Login Item for the user that points to a script within the app package, instead of pointing to the app itself (see below), at least for me.

image

If the login item would just point to the application itself, it would work as intended, with no terminal window.

Looking at the code, if you use electron and do not specify opts.path when you call the AutoLaunch constructor, it will just pick the path from process.execPath (see https://github.com/Teamwork/node-auto-launch/blob/master/src/index.coffee#L23).

After that fixOpts is called which in turns calls @fixMacExecPath that "corrects the path to point to the outer .app" if you are running on "darwin". @fixMacExecPath uses a regular expression to correct the path, and this could be where the issue is for the ones running into the problem.

from node-auto-launch.

orther avatar orther commented on July 19, 2024 2

For NW.js the solution provided by @nickaversano works (only tested with [email protected]).

The following is code from my project. It fixes the path on OS X and removes the bad login item nwjs Helper that could exist from before fix was put in place:

function getCurrentApplicationPath() {
    if (global.process.platform === 'darwin') {
        return global.process.execPath.split('.app/Content')[0] + '.app';
    }
    return null;
};

const bootLauncher = new AutoLaunch({
    name: APP_NAME,
    path: getCurrentApplicationPath(),
    isHidden: false,
});

// remove any existing `nwjs Helper` login item on app start
bootLauncher.removeNwjsLoginItem();

from node-auto-launch.

fretman92 avatar fretman92 commented on July 19, 2024 2

Pull request that can solve that: #34

from node-auto-launch.

sujkh85 avatar sujkh85 commented on July 19, 2024 1

@adam-lynch yes use Electron
use main process

function initAutoLaunch() {
	if (autoLauncher) {
        return;
    }
	let appPath = process.platform === 'darwin' ? (app.getPath('exe').split('.app/Content')[0] + '.app') : app.getPath('exe')

    autoLauncher = new AutoLaunch({
        name: 'myApp',
		path: appPath,
                isHidden: false,
		mac:{
			useLaunchAgent:true
		}
    });
}

ipcMain is electron object

    ipcMain.on('SET_AUTO_LAUNCH', (event, arg) => {
        let result = arg.enabled ? autoLauncher.enable() : autoLauncher.disable();
        result.then(() => {
           console.log('autoLaunch','autoLauncher success');
        }).catch(() => {
           console.log('autoLaunch','autoLauncher error');
        })
    });

from node-auto-launch.

Dihgg avatar Dihgg commented on July 19, 2024

@luhfilho
I also have this problem, within a similar configuration.

from node-auto-launch.

CHENGP618 avatar CHENGP618 commented on July 19, 2024

some here

from node-auto-launch.

luhfilho avatar luhfilho commented on July 19, 2024

@CHENGP618 @Dihgg
I solved my problem with this fix

if(process.platform !== 'darwin')
{
    //auto lauch test
    var appLauncher = new AutoLaunch({
        'name': appName
    });
    appLauncher.isEnabled().then((enabled) => {
        if (enabled) return;
        return appLauncher.enable()
    }).then((err) => {});
}
else
{
    const username = require('username');
    username().then(username => {
        //=> 'sindresorhus'
        var osxExecutable = '/Applications/AppName.app';
        var osxStartFile =  '/User/'+username+'/Library/LaunchAgents/AppName.plist';

        var exists = fs.existsSync(osxStartFile);
        if (!exists) {
            var osxData = '<?xml version="1.0" encoding="UTF-8"?>\r\n'+
                            '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\r\n'+
                            '<plist version="1.0">\r\n'+
                            '<dict>\r\n'+
                                '<key>ProgramArguments</key>\r\n'+
                                '<array>\r\n'+
                                '    <string>'+osxExecutable+'</string>\r\n'+
                                '</array>\r\n'+
                                '<key>RunAtLoad</key>\r\n'+
                                '<true/>\r\n'+
                                '<key>'+appName+'</key>\r\n'+
                                '<string>'+appId+'</string>\r\n'+
                            '</dict>\r\n'+
                            '</plist>';
            fs.writeFile(osxStartFile, osxData);
        }
    });
}

I used username module, to get OS username folder to save plist file, this way, the OSX system will open your app on startup.

from node-auto-launch.

Dihgg avatar Dihgg commented on July 19, 2024

@CHENGP618 @luhfilho, Also worked for me, a kind of workaround.

from node-auto-launch.

nickav avatar nickav commented on July 19, 2024

What version of Mac is this happening on? Works for me on 10.9.5

from node-auto-launch.

luhfilho avatar luhfilho commented on July 19, 2024

@nickaversano 10.11.5 version

from node-auto-launch.

CHENGP618 avatar CHENGP618 commented on July 19, 2024

@Dihgg @luhfilho couldn't work for me, version 10.11.4, anything special to take care?

<key>Label</key>

<string>com.sigilium.addressbook</string>

<key>ProgramArguments</key>

<array>

  <string>/Applications/sigiliumaddressbook.app</string>

</array>

<key>RunAtLoad</key>

<true/>

from node-auto-launch.

nickav avatar nickav commented on July 19, 2024

@djpereira what is your process.execPath on OSX 10.11? On 10.9 it is: ./node_modules/electron-prebuilt/dist/Electron.app/Contents/MacOS/Electron
When run through @fixMacExecPath, it truncates everything after Electron.app which gives the desired effect.

The interesting thing to note is that @fixMacExecPath uses MacOS\/Electron in its regular expression. When running packaged electron apps, Electron won't match the app name.

from node-auto-launch.

djpereira avatar djpereira commented on July 19, 2024

Thanks for asking @nickaversano. The process.execPath for in OSX 10.11 for our app is /Applications/My Electron App.app/Contents/Frameworks/My Electron App Helper.app/Contents/MacOS/My Electron App Helper

We do have white spaces in our app name, not sure if that's an issue.

from node-auto-launch.

nickav avatar nickav commented on July 19, 2024

@djpereira this definitely isn't a spacing issue. Happens to me on an app without spaces. Like you mentioned, I think this is happening because @fixPath fails to return the correct application path. I'm fairly confident this happens in packaged applications because 'Electron' would be renamed to the new app name but @fixMacExecPath uses a regular expression with a hardcoded 'Electron' which would fail to match.

from node-auto-launch.

djpereira avatar djpereira commented on July 19, 2024

Thanks for the workaround @nickaversano. This worked very well for me.

from node-auto-launch.

adam-lynch avatar adam-lynch commented on July 19, 2024

Hey everyone, could you please confirm if #38 fixes this?

from node-auto-launch.

mzdr avatar mzdr commented on July 19, 2024

Nope, I think there is still a bug. Will share details in #38.

from node-auto-launch.

todbot avatar todbot commented on July 19, 2024

I was also having this problem (I've not yet tested #38), but here's the hack I used on Electron to get it to work for me:

var appPath = app.getAppPath();
if( process.platform === 'darwin' ) { 
    appPath = path.resolve( appPath, '../../..'); // MyApp.app/Contents/Resources/app.asar
}
var AutoLauncher = new AutoLaunch({
    name: 'Blink1Control2', 
    path: appPath
});

(I'm using asar to pack my app, which is why there's 3 '..')

from node-auto-launch.

adam-lynch avatar adam-lynch commented on July 19, 2024

OK I've just released 5.0.0. Please give that a try and let me know if the issue persists. If so, also try the new Launch Agent option.

If it still persists, I'm going to need more information and probably an example app. I need the versions of what you're using, the options being passed to our module, if you're using it in the Electron main or renderer process, and what your process.execPath is.

If your problem has been solved, please let us know too. Thanks.

from node-auto-launch.

omichelsen avatar omichelsen commented on July 19, 2024

The issue persists, still seeing the Terminal on Mac. Windows is fine.

from node-auto-launch.

sujkh85 avatar sujkh85 commented on July 19, 2024

some here
osx v10.11.6
eletron v1.4.x

    new AutoLaunch({
            name: 'me',
            path: app.getPath('exe'),
            isHidden: false,
            mac:{
                useLaunchAgent:true
            }
        });

from node-auto-launch.

sujkh85 avatar sujkh85 commented on July 19, 2024

@orther right

let appPath = app.getPath('exe').split('.app/Content')[0] + '.app';
new AutoLaunch({
            name: 'me',
            path: appPath,
            isHidden: false,
        });

from node-auto-launch.

adam-lynch avatar adam-lynch commented on July 19, 2024

@omichelsen @sujkh85

Are you using Electron? If so, in the main or a renderer process?
Is there any chance you could share a simple sample app which reproduces this?

from node-auto-launch.

omichelsen avatar omichelsen commented on July 19, 2024

Using OSX 10.12.1 and Electron 1.4.3. Triggering this in the main process. Using the "fix" @sujkh85 suggests (only on Mac) fixes it for me.

from node-auto-launch.

 avatar commented on July 19, 2024

I have found a difference between usage of useLaunchAgent to launch electron app:

If true, you have to specify path as app.getPath('exe') provides (without split last part)
If false: you have to split path to be blablabla.app

Does it work for all?

from node-auto-launch.

tiangolo avatar tiangolo commented on July 19, 2024

I was having this issue in macOS, for an electron app built with electron-builder.

But after changing the option to set the auto launcher using a "launch agent" as described in https://github.com/Teamwork/node-auto-launch#launch-agent it worked without a problem.

Here's the relevant code I had:

const autoLaunch = new AutoLaunch({
    name: app.getName(),
  });

And I changed it to:

const autoLaunch = new AutoLaunch({
    mac: {
      useLaunchAgent: true,
    },
    name: app.getName(),
  });

That solved the issue, at least in my case.

from node-auto-launch.

jssuttles avatar jssuttles commented on July 19, 2024

For nwjs .apps, the solution is definitely along the lines of @orther's solution. That works.
(without the .removeNwjsLoginItem which is old)

from node-auto-launch.

adam-lynch avatar adam-lynch commented on July 19, 2024

Apologies, we've neglected this project a little bit. We're going to fix that though, see #64. I'm going to put in some time this Saturday. If someone could provide a simple app by then that reproduces this (or if it's simply the Electron hello world app), then that would help things along.

from node-auto-launch.

adam-lynch avatar adam-lynch commented on July 19, 2024

I've just published 5.0.2 which should fix this. Let me know if not.

@luhfilho @djpereira @nickaversano @guerrerocarlos since you all looked into the code a bit... I don't know if you saw #64 but we're looking to bring add some contributors/maintainers to help with:

  • Improving documentation.
  • Troubleshoot, triage, and reproduce issues on your machine.
  • Fix bugs.
  • General maintenance (dependencies, etc).
  • Suggest & add features.
  • Review, test, and merge pull-requests from other contributors.
  • Anything else you can think of which would help.

Would you be open to that? I can give you access.

from node-auto-launch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.