Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Manipulate WindowOptions #360

Open
Happy-Ferret opened this issue Apr 19, 2022 · 5 comments
Open

Manipulate WindowOptions #360

Happy-Ferret opened this issue Apr 19, 2022 · 5 comments

Comments

@Happy-Ferret
Copy link
Contributor

Happy-Ferret commented Apr 19, 2022

I'd like to dynamically set AlwaysOnTop based on a setting inside my app.

Is there a way to access the WindowOptions outside the bootstrapping procedure (I've been unable to find it, or rather direct access is private) or will I have to make-do with require("electron").remote.BrowserWindow.getFocusedWindow().setAlwaysOnTop(bool_value) from inside JS? I'd rather like to avoid doing it like this.

@asticode
Copy link
Owner

Right now this is not possible in GO but adding it is not that complex. I just won't have time to work on this anytime time soon though. If you feel like it, I can describe what has to be done so that you can make a PR

@Happy-Ferret
Copy link
Contributor Author

Right now this is not possible in GO but adding it is not that complex. I just won't have time to work on this anytime time soon though. If you feel like it, I can describe what has to be done so that you can make a PR

I think I know what needs to be done.
Something similar to w.OpenDevTools(), I assume?

w.Sticky(astikit.BoolPtr), perhaps?

@Happy-Ferret
Copy link
Contributor Author

Happy-Ferret commented Apr 19, 2022

Weird. I tried adding the changes that, to the best of my knowledge, are necessary but end up with a no-op.

Any idea what I'm doing wrong?

window.go:

...
// Window event names
const (
...
	EventNameWindowCmdSetAlwaysOnTop			  = "window.cmd.set.always.on.top"
	EventNameWindowEventAlwaysOnTopChanged			  = "window.event.always.on.top.changed"
...

func (w *Window) SetAlwaysOnTop(flag bool) (err error) {
	if err = w.ctx.Err(); err != nil {
		return
	}
	w.m.Lock()
	w.o.AlwaysOnTop = astikit.BoolPtr(flag)
	w.m.Unlock()
	_, err = synchronousEvent(w.ctx, w, w.w, Event{Name: EventNameWindowCmdSetAlwaysOnTop, TargetID: w.id, WindowOptions: &WindowOptions{AlwaysOnTop: astikit.BoolPtr(flag)}}, EventNameWindowEventAlwaysOnTopChanged)
	return
}

App

message.go

package desktop

import (
	"github.com/asticode/go-astilectron"
	"github.com/asticode/go-astilectron-bootstrap"
)

func HandleMessages(w *astilectron.Window, m bootstrap.MessageIn) (payload interface{}, err error) {
	switch m.Name {
	case "always_on_top":
		w.SetAlwaysOnTop(true)
		payload = "AlwaysOnTop set"
		return
	}
	return
}

app.js

astilectron.sendMessage(
        { name: "always_on_top", payload: "" },
        message => {
        console.log("received " + message)
    });

@asticode
Copy link
Owner

You need to update astilectron (the JS part) as well so that it parses the new window.cmd.set.always.on.top key 👍

@Happy-Ferret
Copy link
Contributor Author

Happy-Ferret commented Apr 19, 2022

You need to update astilectron (the JS part) as well so that it parses the new window.cmd.set.always.on.top key 👍

How do I ensure the correct astilectron js is being used?
I edited the files inside %APPDATA%//vendor/astilectron but it doesn't seem to use those.

EDIT: NVM. It is being used.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants