go-astilectron icon indicating copy to clipboard operation
go-astilectron copied to clipboard

Notification must set user model id on win32

Open txthinking opened this issue 6 years ago • 7 comments

I did not find the setappusermodelid api on godoc.

https://electronjs.org/docs/api/app#appsetappusermodelidid-windows

BTW, can we set app id custom like com.mydomain.app

Thanks

txthinking avatar Oct 13 '18 07:10 txthinking

@txthinking ok for app.setAppUserModelId(id).

But regarding your second question, can you point to the Electron corresponding doc?

asticode avatar Oct 13 '18 17:10 asticode

Sorry for the unclear description. https://www.electron.build/configuration/configuration#configuration

txthinking avatar Oct 14 '18 09:10 txthinking

thanks!

asticode avatar Oct 14 '18 10:10 asticode

I spent some time and found the solution and shared it with the people who needed it.


I using the astilectron 0.27| astilectron: 0.51.0 | Electron 11.4.3

I can wait for provision to finish downloading and processing all the related files and then modifying index.js

where "index.js" is located on: https://github.com/asticode/go-astilectron/blob/e7796e5/paths.go#L62

if os:windows default path: %appdata%/[appName]/vendor/astilectron/index.js

// App is ready
function onReady () {
    app.setAppUserModelId("com.mydomain.app");  //  👈  Add this line.  default: electron.app.Electron. 
    // Init
    const screen = electron.screen
    Menu.setApplicationMenu(null)
    ...

But I think this method is still very bad, I hope that the code can be changed directly in the go🤔


see also

CarsonSlovoka avatar Mar 16 '22 11:03 CarsonSlovoka

Yeah, I think that an AppUserModelID should be added in the Options.

I won't have time to work on this anytime soon, but if someone is looking to contribute, feel free to let me know and I'll guide you to make a PR.

asticode avatar Mar 16 '22 11:03 asticode

I'm trying to use the event to change the ID,

I with it can add on notificationCreate

but it doesn't work. It seems that the event has to be determined after the end of onReady. Even if the hard coding can't change the ID later, for example

    rl.on('line', function(line){
        app.setAppUserModelId("hello world")  // 👈 still not work.
        // Parse the JSON
        let json = JSON.parse(line)

        // Switch on event name
        let window;

I don't know if my inference is wrong or not, but the result of my experiment is indeed like this.


I noticed that atilectron is not a big repository, I want to use embedgo1.16 embed in go-astilectron to embed it directly so that there is no need to maintain two repositories, and even in the js directly using text/template, we can set some initialization place to supply the user to write the code directly into the js, will become very flexible.

Would you accept the pull request like it?

CarsonSlovoka avatar Mar 21 '22 03:03 CarsonSlovoka

  1. Indeed, the best would be to add the AppUserModelID as an attribute to Options so that it gets set right at the start of astilectron

  2. We can't merge go-astilectron and astilectron since some people are using astilectron without go and need this repository to exist independently from go-astilectron

asticode avatar Mar 21 '22 10:03 asticode