Skip to content

Commit

Permalink
Fix modifier processing on windows.
Browse files Browse the repository at this point in the history
Move info logs to debug.
  • Loading branch information
leaanthony committed Oct 15, 2023
1 parent 2269f64 commit 7795a2a
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
4 changes: 1 addition & 3 deletions v3/examples/keybindings/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
_ "embed"
"github.com/wailsapp/wails/v3/pkg/application"
"log"
"log/slog"
)

func main() {
Expand All @@ -15,11 +14,10 @@ func main() {
ApplicationShouldTerminateAfterLastWindowClosed: true,
},
KeyBindings: map[string]func(window *application.WebviewWindow){
"F11": func(window *application.WebviewWindow) {
"shift+ctrl+c": func(window *application.WebviewWindow) {
window.Center()
},
},
LogLevel: slog.LevelDebug,
})

app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
Expand Down
4 changes: 2 additions & 2 deletions v3/pkg/application/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (b *Bindings) AddPlugins(plugins map[string]Plugin) error {
}
b.boundMethods[packageName][structName][methodName] = method
b.boundByID[method.ID] = method
globalApplication.info("Added plugin method: "+structName+"."+methodName, "id", method.ID)
globalApplication.debug("Added plugin method: "+structName+"."+methodName, "id", method.ID)
}
}
return nil
Expand Down Expand Up @@ -265,7 +265,7 @@ func (b *Bindings) getMethods(value interface{}, isPlugin bool) ([]*BoundMethod,
args = append(args, "alias", alias)
}
}
globalApplication.info("Adding method:", args...)
globalApplication.debug("Adding method:", args...)
}
// Iterate inputs
methodType := method.Type()
Expand Down
13 changes: 7 additions & 6 deletions v3/pkg/application/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ type accelerator struct {
}

func (a *accelerator) String() string {
result := strings.Builder{}
var result []string
// Sort modifiers
slices.Sort(a.Modifiers)
for _, modifier := range a.Modifiers {
result.WriteString(modifier.String())
result.WriteString("+")
result = append(result, modifier.String())
}
result.WriteString(a.Key)
return strings.ToLower(result.String())
slices.Sort(result)
if len(a.Key) > 0 {
result = append(result, a.Key)
}
return strings.ToLower(strings.Join(result, "+"))
}

var namedKeys = map[string]struct{}{
Expand Down
2 changes: 1 addition & 1 deletion v3/pkg/application/keys_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var VirtualKeyCodes = map[uint]string{
0x0C: "clear",
0x0D: "return",
0x10: "shift",
0x11: "control",
0x11: "ctrl",
0x12: "menu",
0x13: "pause",
0x14: "capital",
Expand Down
4 changes: 2 additions & 2 deletions v3/pkg/application/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ func (p *PluginManager) Init() error {
if injectJS != "" {
p.assetServer.AddPluginScript(plugin.Name(), injectJS)
}
globalApplication.info("Plugin initialised: " + plugin.Name())
globalApplication.debug("Plugin initialised: " + plugin.Name())
}
return nil
}

func (p *PluginManager) Shutdown() {
for _, plugin := range p.initialisedPlugins {
plugin.Shutdown()
globalApplication.info("Plugin shutdown: " + plugin.Name())
globalApplication.debug("Plugin shutdown: " + plugin.Name())
}
}
4 changes: 2 additions & 2 deletions v3/pkg/application/systemtray_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (s *windowsSystemTray) run() {
// Set Default Callbacks
if s.parent.clickHandler == nil {
s.parent.clickHandler = func() {
globalApplication.info("Left Button Clicked")
globalApplication.debug("Left Button Clicked")
}
}
if s.parent.rightClickHandler == nil {
Expand Down Expand Up @@ -347,6 +347,6 @@ func (s *windowsSystemTray) destroy() {
// Destroy the notification icon
nid := s.newNotifyIconData()
if !w32.ShellNotifyIcon(w32.NIM_DELETE, &nid) {
globalApplication.info(syscall.GetLastError().Error())
globalApplication.debug(syscall.GetLastError().Error())
}
}
2 changes: 1 addition & 1 deletion v3/pkg/application/webview_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func processKeyBindingOptions(keyBindings map[string]func(window *WebviewWindow)
continue
}
result[acc.String()] = callback
globalApplication.info("Added Keybinding", "accelerator", acc.String())
globalApplication.debug("Added Keybinding", "accelerator", acc.String())
}
return result
}
Expand Down
4 changes: 2 additions & 2 deletions v3/pkg/application/webview_window_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -888,12 +888,12 @@ func (w *macosWebviewWindow) toggleDevTools() {

func (w *macosWebviewWindow) reload() {
//TODO: Implement
globalApplication.info("reload called on WebviewWindow", "parentID", w.parent.id)
globalApplication.debug("reload called on WebviewWindow", "parentID", w.parent.id)
}

func (w *macosWebviewWindow) forceReload() {
//TODO: Implement
globalApplication.info("force reload called on WebviewWindow", "parentID", w.parent.id)
globalApplication.debug("force reload called on WebviewWindow", "parentID", w.parent.id)
}

func (w *macosWebviewWindow) center() {
Expand Down
13 changes: 7 additions & 6 deletions v3/pkg/application/webview_window_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -1469,14 +1469,15 @@ func (w *windowsWebviewWindow) processKeyBinding(vkey uint) bool {
acc.Modifiers = append(acc.Modifiers, SuperKey)
}

// Convert the vkey to a string
accKey, ok := VirtualKeyCodes[vkey]
if !ok {
return false
if vkey != w32.VK_CONTROL && vkey != w32.VK_MENU && vkey != w32.VK_SHIFT && vkey != w32.VK_LWIN && vkey != w32.VK_RWIN {
// Convert the vkey to a string
accKey, ok := VirtualKeyCodes[vkey]
if !ok {
return false
}
acc.Key = accKey
}

acc.Key = accKey

// Process the key binding
return w.parent.processKeyBinding(acc.String())

Expand Down

0 comments on commit 7795a2a

Please sign in to comment.