asticode / go-astilectron

Build cross platform GUI apps with GO and HTML/JS/CSS (powered by Electron)
MIT License
4.91k stars 345 forks source link

Dock (w/ Bootstrap & Bundler) produces JS error #164

Open adambrakhane opened 5 years ago

adambrakhane commented 5 years ago

When I set the dock icon on Mac it correctly sets the image but I get a Javascript exception on launch. Other than that, everything seems to run OK. My code is just slightly modified from the demo repo.

OnWait: func(a *astilectron.Astilectron, ws []*astilectron.Window, _ *astilectron.Menu, _ *astilectron.Tray, _ *astilectron.Menu) error {
            // Get the dock
            var d = a.Dock()
            // Update icon

            d.SetIcon("resources/icon-book512.png")
            // <The rest of the demo code for OnWait is here>
        },

The javascript exception is:

Uncaught Exception: TypeError: Error processing argument at index 0, conversion failure from resources/icon-book512.png at Interface. (/Users/adam/projects/chispa/goapp/src/invenstory/output/darwin-amd64/InvenStory.app/Contents/MacOS/vendor/astilectron/main.js:125:26) at Interface.emit (events.js:182:13) at Interface._onLine (readline.js:290:10) at Interface._normalWrite (readline.js:433:12) at Socket.ondata (readline.js:149:10) at Socket.emit (events.js:182:13) at addChunk (_stream_readable.js:283:12) at readableAddChunk (_stream_readable.js:264:11) at Socket.Readable.push (_stream_readable.js:219:10) at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

On a different note, I tried to use the Astilectron Adapter function in the bootstrap run function and while the a pointer is not nil, a.Dock() is always nil. That's why I moved to trying in OnWait. Adapter: func(a *astilectron.Astilectron) {a.Dock() == nil // True},

asticode commented 5 years ago

1) My guess is this happens because you provide a relative path. Can you try using something like filepath.Join(a.Paths.DataDirectory(), "resources", "icon-book512.png") ?

2) This is normal that a.Dock() is nil in the Adapter since it's executed just after the calling astilectron.New and even before disembedding resources. Using OnWait is a great choice!

adambrakhane commented 5 years ago

No luck. I verified that it was actually giving the correct path out. The icon is correct, but I get the error.

I also found that it was only the bundled app that failed to load correctly. When I run the binary (./output/darwin-amd64/application.app/Contents/MacOS/application) the correct icon appears and there is no JS error. When I open the actual .app file, I get the correct icon, but also the JS alert.

asticode commented 5 years ago

Mmmm this is a really weird one... could you try converting your icon to .icns and let me know whether you still get the error?

adambrakhane commented 5 years ago

Same story. I referenced the same icns file that I use in AppIconDarwinPath: "resources/icon-book.icns", and tried with relative & full path.

adambrakhane commented 5 years ago

If it helps, I added some dialogs prints to print out those dock and JSON variables:

            if (typeof app.dock !== "undefined") {
                dialog.showErrorBox("DOCK", "content")
                dialog.showErrorBox("json", JSON.stringify(json))
                dialog.showErrorBox("app", JSON.stringify(app))
                app.dock.setIcon(json.image);
            }
JSON.stringify(json)={"name":"dock.cmd.set.icon","targetID":"dock","image":"/Users/adam/projects/chispa/goapp/src/invenstory/resources/icon-book.icns"}
JSON.stringify(app)={"_events":{},"_eventsCount":10,"commandLine":{},"isPackaged":true,"dock":{}}

Maybe there's something to the fact that dock is empty? Maybe it's just functions and whatnot and wouldn't be printed anyway? Merely commenting out app.dock.setIcon(json.image); is enough to stop the exception.

asticode commented 5 years ago

Could you try moving the app to the Applications folder and try again ?

adambrakhane commented 5 years ago

Same thing.