fix: create platform specific init

This commit is contained in:
Lea Anthony 2019-11-28 22:47:41 +11:00
commit 401ebee719
3 changed files with 36 additions and 19 deletions

21
app.go
View file

@ -1,7 +1,6 @@
package wails
import (
"fmt"
"os"
"runtime"
"syscall"
@ -67,28 +66,12 @@ func CreateApp(optionalConfig ...*AppConfig) *App {
result.config.DisableInspector = true
}
// If running windows, do a hidpi fix
if runtime.GOOS == "windows" {
err := SetProcessDPIAware()
if err != nil {
result.log.Fatalf(err.Error())
}
}
// Platform specific init
platformInit()
return result
}
// SetProcessDPIAware via user32.dll
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiaware
// Also, thanks Jack Mordaunt! https://github.com/wailsapp/wails/issues/293
func SetProcessDPIAware() error {
status, r, err := syscall.NewLazyDLL("user32.dll").NewProc("SetProcessDPIAware").Call()
if status == 0 {
return fmt.Errorf("exit status %d: %v %v", status, r, err)
}
return nil
}
// Run the app
func (a *App) Run() error {

7
app_other.go Normal file
View file

@ -0,0 +1,7 @@
// +build +linux +darwin !windows
package wails
func platformInit() {
}

27
app_windows.go Normal file
View file

@ -0,0 +1,27 @@
// +build windows !linux !darwin
package wails
import (
"fmt"
"log"
"syscall"
)
func platformInit() {
err := SetProcessDPIAware()
if err != nil {
log.Fatalf(err.Error())
}
}
// SetProcessDPIAware via user32.dll
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiaware
// Also, thanks Jack Mordaunt! https://github.com/wailsapp/wails/issues/293
func SetProcessDPIAware() error {
status, r, err := syscall.NewLazyDLL("user32.dll").NewProc("SetProcessDPIAware").Call()
if status == 0 {
return fmt.Errorf("exit status %d: %v %v", status, r, err)
}
return nil
}