-
Notifications
You must be signed in to change notification settings - Fork 15k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support LoginItem API in Mac App Store builds #7312
Comments
Because @kevinsawicki just recently implemented them! 🎉 |
Ah hey @zeke. I discovered them via your mojibar PR 😄.
Oh... I thought I saw the commits were from July 😄 |
Aforementioned PR: muan/mojibar#50 July is recent, no? :) |
According to this article:
So LoginItem API methods are not MAS compatible. |
I wonder if auto-launch works. |
@zcbenz OK thanks. Do you think it's possible at all? Maybe if it was implemented differently? This article, Modern Login Items, describes a way to achieve it but it requires an extra app (as well as your main app). If you see electron-userland/electron-builder#756, I thought it might be possible if electron-builder were to give you the extra app* and Electron were to expose an API method to toggle the "user preference." * Although maybe this extra app could even be provided by Electron itself? I don't know. It would have to be signed though. @zeke no, see Teamwork/node-auto-launch#43. I'm no expert though. |
I'm so confused as to what the Helper does in that blog post - like, why do you need it if they're both sandboxed and have the same privileges? |
I didn't look deeply into those articles, it seems that they work by adding a daemon to system with services framework and then start the app from the daemon. It should be possible to provide a builtin solution in Electron. |
Sure, but if you've got the privileges to register the daemon, can't you just register the app directly? |
Is there a workaround for this? The idea is there are a few types of applications. MAS compatible Login Items can be either
So you cannot make a proper app (non-agent, with docker icon) a login item. I don't know how exactly electron apps are bundled, but login items should be possible by building a cocoa app into |
I'm closing this as won't fix since Apple simply does not provide an official way to do this. |
OK too bad, thanks @zcbenz. |
Apple does provide an official way and documentation to do this (via the helper app):
|
@fab1an It is great to know there is an API to do that! I'm reopening this issue. |
I will try to get this to work and report my findings the next couple of days. |
Ok, I am taking time to write this up, because I hope someone will come along and automate it. The following official way works for me in sandboxed, production-signed Step 1: Helper App
Step 2: Include the helper in your appAdd the following to your electron-builder-config:
Step 3: Verify it worksBuild a
This should start your main-application, the helper merely starts the application three folder up in it's hierarchy. This should work no matter if your contained app is signed or not, sandboxed, or not. Step 4: Call it from your mainApp.
module.exports = function SMLoginItemSetEnabled(appId, enabled) {
const ffiLibrary = require("./ffiLibraryPatched.js")
const smLib = ffiLibrary(
"/System/Library/Frameworks/ServiceManagement.framework/Versions/A/ServiceManagement",
{
SMLoginItemSetEnabled: ["bool", ["pointer", "bool"]]
},
null,
{appendExtension: false}
)
const objc = ffiLibrary(null, {
objc_getClass: ["pointer", ["string"]],
sel_registerName: ["pointer", ["string"]]
}),
objcSend_PtrPtrStr = ffiLibrary(null, {
objc_msgSend: ["pointer", ["pointer", "pointer", "string"]]
}),
$C = v => objc.objc_getClass(v),
$R = v => objc.sel_registerName(v);
const appId_cfString = objcSend_PtrPtrStr.objc_msgSend($C("NSString"), $R("stringWithUTF8String:"), appId)
return smLib.SMLoginItemSetEnabled(appId_cfString, enabled);
} Step 5: Build your app
console.log("enabling, sucess: ", SMLoginItemSetEnabled("myapp.loginhelper", true))
console.log("disabling, sucess: ", SMLoginItemSetEnabled("myapp.loginhelper", false))
Step 6: SuccessIf everything went smoothly your app should now be able to set the login-helper to start at login which, in turn starts your app and then terminates. Troubleshooting and known problems:
Happy hacking. |
@fab1an Thanks for the guide. Just to be clear. Is the above guide Mac App Store friendly? Will it pass review? |
@holgersindbaek It works yes, my app is on sale by now. Be sure to check out electron-userland/electron-builder#2035 as well, though. |
@fab1an Nice. Thanks. I'll check it out. I'll probably try to implement tomorrow or so. I hope it goes smoothly :-). |
@fab1an I'm going through your guide now, but I'm stuck on step 4. Can you be a bit more specific with what I need to do there? Questions I have:
|
@holgersindbaek Hi Holger, did the API will only work when called from a correctly production-signed bundle, did you try that? |
I haven’t tried that yet. Does the app have to be in the application directory as well? Is the only way to confirm that it works, to restart your Mac? Or is there a faster way?
…--
All the best
*Holger Sindbaek* · UI/UX Designer & Web/iOS Programmer · * * OnlineSolitaire.com ( http://onlinesolitaire.com/ )
On Tue, Oct 17, 2017 at 5:57 AM Fabian Zeindl < Fabian Zeindl ( Fabian Zeindl ***@***.***> ) > wrote:
@holgersindbaek ( https://github.com/holgersindbaek ) Hi Holger, did the
API will only work when called from a correctly production-signed bundle,
did you try that?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (
#7312 (comment) ) ,
or mute the thread (
https://github.com/notifications/unsubscribe-auth/AAqqY4dK9BswK8vN1S5fPoBX1SGu_782ks5stCWbgaJpZM4KEWVI
).
|
If I build a distribution build (MAS build), then I can't open the app locally on my computer. I get the following error:
From what I understand, the app is supposed to crash if it's signed with a distribution profile and opened locally on the computer (electron/osx-sign#130). That still leaves the question of... how do I verify that this actually works? From what I gather, the only way for me to verify that this works, is to push the app for MAS review, have it go through, download the app and then test it. Am I wrong? |
@holgersindbaek You can run codesign -dvvv sample.app to check the signature. EXC_CRASH (Code Signature Invalid) indicates that the package was modified after signing. |
@robinwassen Are you saying that the crash is not to be expected? From what I understand from this issue - electron/osx-sign#130 - the app is expected to crash when build using distribution signature? Is there a way to sign the app with a distribution signature and still open it? |
@holgersindbaek No the app doesn't have to be in the application directory, but it has to be sandboxed and signed. The helper needs proper permissions as well: electron-userland/electron-builder#2035. |
@fab1an Does it need to be signed with a distribution profile for the app store? I've tried to get it to work, but signing both the main app and the helper app with a developer profile, but that didn't work. I got The helper app seems to have the correct permissions:
|
@holgersindbaek Yes, you need a profile. It works for 3rd-party-signed applications as well (Mac Apps, not MAS). Did you check whether all your appIds are registered correctly? |
@fab1an If I sign my application with a 3rd party signature, then the app crashes as documented above. Can you share you "build" section from your package.json? My main app has the app ID "com.betaunltd.solitaire-game-center", which is registered in my developer portal. My helper app has the app ID "com.betaunltd.solitaire-game-center.login-helper". I haven't registered that in my developer portal. Is that necessary? |
@holgersindbaek Sorry, I can't share my build, as I don't use JavaScript, but Gradle instead. It's not easily reproducible for others. Yes, you have to register your helper app as well. |
@holgersindbaek You don't have to wait for MAS review. Are you able to build a production signed MAC-application? Not MAS, but direct distribution, so that other Macs can open that app. With such an application it will work, and you can test it locally. Here is the relevant part of my electron-build process:
The I have a
|
Hmm, ok. I'll try to create a Mac production provisioning profile as well then. Is it important that the helper app and the main app is signed with the same signature? I seem to remember seeing the |
Do that. I don't know whether the need to have the same signature, please report back if you find something out.
|
Is this implemented now? What do we need to do to be able to use the login helper? |
Reopened due to #10856 being reverted by #11140 :P See #10856 (comment) for details |
Closed with #11144. |
Thanks everyone. |
👏 well done & thanks |
I want to point some attention to the fact that after #15010 The Also there is an issue now with the lack of app in the login items list in System Preferences |
It seems that autolaunch for MAS is not working, I filed an issue with the details I could find |
I don't know how I've only discovered these methods now 😄 but anyway...
Would an app get rejected by the MAS if it used
app.setLoginItemSettings
for example? The Mac App Store submission guide doesn't list it as a limitation but I would assume that it isn't MAS-friendly. Although, it would be great if it was compatible. I guess it depends on how it's implemented underneath (i.e. whether it reaches out of the sandbox or not, etc.)cc @kevinsawicki
Related: Teamwork/node-auto-launch#43
The text was updated successfully, but these errors were encountered: