mirror of
https://github.com/jahruz67/wisp-open.git
synced 2026-08-08 18:14:08 +00:00
fix: improve global shortcut signal handling and logging in Linux portal
This commit is contained in:
@@ -343,26 +343,18 @@ func (hk *Hotkey) portalSignalLoop() {
|
|||||||
|
|
||||||
hk.mu.Lock()
|
hk.mu.Lock()
|
||||||
conn := hk.portalConn
|
conn := hk.portalConn
|
||||||
sess := hk.sessionPath
|
|
||||||
hk.mu.Unlock()
|
hk.mu.Unlock()
|
||||||
if conn == nil {
|
if conn == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sessStr := string(sess)
|
|
||||||
var token string
|
|
||||||
if idx := strings.LastIndex(sessStr, "/"); idx != -1 {
|
|
||||||
token = sessStr[idx+1:]
|
|
||||||
} else {
|
|
||||||
token = sessStr
|
|
||||||
}
|
|
||||||
|
|
||||||
ch := make(chan *dbus.Signal, 32)
|
ch := make(chan *dbus.Signal, 32)
|
||||||
conn.Signal(ch)
|
conn.Signal(ch)
|
||||||
defer conn.RemoveSignal(ch)
|
defer conn.RemoveSignal(ch)
|
||||||
|
|
||||||
rule := fmt.Sprintf(
|
rule := fmt.Sprintf(
|
||||||
"type='signal',interface='%s'",
|
"type='signal',sender='%s',interface='%s'",
|
||||||
ifaceGlobalShortcuts,
|
portalBusName, ifaceGlobalShortcuts,
|
||||||
)
|
)
|
||||||
if err := conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule).Store(); err != nil {
|
if err := conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule).Store(); err != nil {
|
||||||
logger.Error("wis-free-v3 hotkey: AddMatch GlobalShortcuts: %v", err)
|
logger.Error("wis-free-v3 hotkey: AddMatch GlobalShortcuts: %v", err)
|
||||||
@@ -370,7 +362,7 @@ func (hk *Hotkey) portalSignalLoop() {
|
|||||||
}
|
}
|
||||||
defer func() { _ = conn.BusObject().Call("org.freedesktop.DBus.RemoveMatch", 0, rule).Store() }()
|
defer func() { _ = conn.BusObject().Call("org.freedesktop.DBus.RemoveMatch", 0, rule).Store() }()
|
||||||
|
|
||||||
logger.Info("Listening for global shortcut signals. Session token: %s", token)
|
logger.Info("Listening for global shortcut signals (sender=%s, interface=%s)", portalBusName, ifaceGlobalShortcuts)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@@ -383,43 +375,29 @@ func (hk *Hotkey) portalSignalLoop() {
|
|||||||
if len(sig.Body) < 2 {
|
if len(sig.Body) < 2 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rawSess := unwrapVariant(sig.Body[0])
|
|
||||||
var sessVar dbus.ObjectPath
|
|
||||||
switch x := rawSess.(type) {
|
|
||||||
case dbus.ObjectPath:
|
|
||||||
sessVar = x
|
|
||||||
case string:
|
|
||||||
sessVar = dbus.ObjectPath(x)
|
|
||||||
default:
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
sessVarStr := string(sessVar)
|
|
||||||
match := false
|
|
||||||
if sessVar == sess {
|
|
||||||
match = true
|
|
||||||
} else if token != "" && (strings.HasSuffix(sessVarStr, "/"+token) || strings.Contains(sessVarStr, token)) {
|
|
||||||
match = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if !match {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Bypass strict session path checking to avoid mismatch bugs.
|
||||||
|
// The shortcut ID is unique to our application.
|
||||||
rawID := unwrapVariant(sig.Body[1])
|
rawID := unwrapVariant(sig.Body[1])
|
||||||
id, ok := rawID.(string)
|
id, ok := rawID.(string)
|
||||||
if !ok || id != wisfreeGlobalShortcutID {
|
if !ok || id != wisfreeGlobalShortcutID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
name := sig.Name
|
logger.Info("Matched global shortcut signal: name=%s", sig.Name)
|
||||||
logger.Info("Matched global shortcut signal: name=%s", name)
|
|
||||||
|
|
||||||
switch {
|
switch sig.Name {
|
||||||
case name == "Activated" || strings.HasSuffix(name, ".Activated"):
|
case ifaceGlobalShortcuts + ".Activated":
|
||||||
go func() { hk.keydownIn <- Event{} }()
|
go func() { hk.keydownIn <- Event{} }()
|
||||||
case name == "Deactivated" || strings.HasSuffix(name, ".Deactivated"):
|
case ifaceGlobalShortcuts + ".Deactivated":
|
||||||
go func() { hk.keyupIn <- Event{} }()
|
go func() { hk.keyupIn <- Event{} }()
|
||||||
|
default:
|
||||||
|
// Fallback for different bus routing names just in case
|
||||||
|
if strings.HasSuffix(sig.Name, ".Activated") {
|
||||||
|
go func() { hk.keydownIn <- Event{} }()
|
||||||
|
} else if strings.HasSuffix(sig.Name, ".Deactivated") {
|
||||||
|
go func() { hk.keyupIn <- Event{} }()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/wailsapp/wails/v2"
|
"github.com/wailsapp/wails/v2"
|
||||||
"github.com/wailsapp/wails/v2/pkg/options"
|
"github.com/wailsapp/wails/v2/pkg/options"
|
||||||
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
|
||||||
|
"github.com/wailsapp/wails/v2/pkg/options/linux"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Application constants
|
// Application constants
|
||||||
@@ -86,6 +87,9 @@ func main() {
|
|||||||
OnBeforeClose: app.beforeClose,
|
OnBeforeClose: app.beforeClose,
|
||||||
StartHidden: true,
|
StartHidden: true,
|
||||||
Bind: []interface{}{app},
|
Bind: []interface{}{app},
|
||||||
|
Linux: &linux.Options{
|
||||||
|
ProgramName: "wis-free-v3",
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user