mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-03 20:22:08 +08:00
[Windows] Add Suspend/Resume callback support (#1474)
* Add Suspend/Resume callback support * Fix comment
This commit is contained in:
parent
c477100374
commit
381909696b
@ -38,6 +38,27 @@ const (
|
|||||||
GCLP_HBRBACKGROUND int32 = -10
|
GCLP_HBRBACKGROUND int32 = -10
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Power
|
||||||
|
const (
|
||||||
|
// WM_POWERBROADCAST - Notifies applications that a power-management event has occurred.
|
||||||
|
WM_POWERBROADCAST = 536
|
||||||
|
|
||||||
|
// PBT_APMPOWERSTATUSCHANGE - Power status has changed.
|
||||||
|
PBT_APMPOWERSTATUSCHANGE = 10
|
||||||
|
|
||||||
|
// PBT_APMRESUMEAUTOMATIC -Operation is resuming automatically from a low-power state. This message is sent every time the system resumes.
|
||||||
|
PBT_APMRESUMEAUTOMATIC = 18
|
||||||
|
|
||||||
|
// PBT_APMRESUMESUSPEND - Operation is resuming from a low-power state. This message is sent after PBT_APMRESUMEAUTOMATIC if the resume is triggered by user input, such as pressing a key.
|
||||||
|
PBT_APMRESUMESUSPEND = 7
|
||||||
|
|
||||||
|
// PBT_APMSUSPEND - System is suspending operation.
|
||||||
|
PBT_APMSUSPEND = 4
|
||||||
|
|
||||||
|
// PBT_POWERSETTINGCHANGE - A power setting change event has been received.
|
||||||
|
PBT_POWERSETTINGCHANGE = 32787
|
||||||
|
)
|
||||||
|
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb773244.aspx
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb773244.aspx
|
||||||
type MARGINS struct {
|
type MARGINS struct {
|
||||||
CxLeftWidth, CxRightWidth, CyTopHeight, CyBottomHeight int32
|
CxLeftWidth, CxRightWidth, CyTopHeight, CyBottomHeight int32
|
||||||
|
@ -24,6 +24,8 @@ type Window struct {
|
|||||||
isDarkMode bool
|
isDarkMode bool
|
||||||
isActive bool
|
isActive bool
|
||||||
hasBeenShown bool
|
hasBeenShown bool
|
||||||
|
OnSuspend func()
|
||||||
|
OnResume func()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *operatingsystem.WindowsVersionInfo) *Window {
|
func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *operatingsystem.WindowsVersionInfo) *Window {
|
||||||
@ -83,6 +85,8 @@ func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *ope
|
|||||||
result.updateTheme()
|
result.updateTheme()
|
||||||
|
|
||||||
if appoptions.Windows != nil {
|
if appoptions.Windows != nil {
|
||||||
|
result.OnSuspend = appoptions.Windows.OnSuspend
|
||||||
|
result.OnResume = appoptions.Windows.OnResume
|
||||||
if appoptions.Windows.WindowIsTranslucent {
|
if appoptions.Windows.WindowIsTranslucent {
|
||||||
// TODO: Migrate to win32 package
|
// TODO: Migrate to win32 package
|
||||||
if !win32.IsWindowsVersionAtLeast(10, 0, 22579) {
|
if !win32.IsWindowsVersionAtLeast(10, 0, 22579) {
|
||||||
@ -144,6 +148,18 @@ func (w *Window) SetMaxSize(maxWidth int, maxHeight int) {
|
|||||||
func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
|
func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
|
||||||
|
|
||||||
switch msg {
|
switch msg {
|
||||||
|
case win32.WM_POWERBROADCAST:
|
||||||
|
switch wparam {
|
||||||
|
case win32.PBT_APMSUSPEND:
|
||||||
|
if w.OnSuspend != nil {
|
||||||
|
w.OnSuspend()
|
||||||
|
}
|
||||||
|
case win32.PBT_APMRESUMEAUTOMATIC:
|
||||||
|
if w.OnResume != nil {
|
||||||
|
w.OnResume()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case w32.WM_SETTINGCHANGE:
|
case w32.WM_SETTINGCHANGE:
|
||||||
settingChanged := w32.UTF16PtrToString((*uint16)(unsafe.Pointer(lparam)))
|
settingChanged := w32.UTF16PtrToString((*uint16)(unsafe.Pointer(lparam)))
|
||||||
if settingChanged == "ImmersiveColorSet" {
|
if settingChanged == "ImmersiveColorSet" {
|
||||||
@ -154,7 +170,7 @@ func (w *Window) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
|
|||||||
w32.SetFocus(w.Handle())
|
w32.SetFocus(w.Handle())
|
||||||
case w32.WM_MOVE, w32.WM_MOVING:
|
case w32.WM_MOVE, w32.WM_MOVING:
|
||||||
if w.notifyParentWindowPositionChanged != nil {
|
if w.notifyParentWindowPositionChanged != nil {
|
||||||
w.notifyParentWindowPositionChanged()
|
_ = w.notifyParentWindowPositionChanged()
|
||||||
}
|
}
|
||||||
case w32.WM_ACTIVATE:
|
case w32.WM_ACTIVATE:
|
||||||
//if !w.frontendOptions.Frameless {
|
//if !w.frontendOptions.Frameless {
|
||||||
|
@ -86,6 +86,11 @@ type Options struct {
|
|||||||
// ResizeDebounceMS is the amount of time to debounce redraws of webview2
|
// ResizeDebounceMS is the amount of time to debounce redraws of webview2
|
||||||
// when resizing the window
|
// when resizing the window
|
||||||
ResizeDebounceMS uint16
|
ResizeDebounceMS uint16
|
||||||
|
|
||||||
|
// OnSuspend is called when Windows enters low power mode
|
||||||
|
OnSuspend func()
|
||||||
|
// OnResume is called when Windows resumes from low power mode
|
||||||
|
OnResume func()
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultMessages() *Messages {
|
func DefaultMessages() *Messages {
|
||||||
|
@ -520,6 +520,24 @@ Type: uint16
|
|||||||
ResizeDebounceMS is the amount of time to debounce redraws of webview2 when resizing the window.
|
ResizeDebounceMS is the amount of time to debounce redraws of webview2 when resizing the window.
|
||||||
The default value (0) will perform redraws as fast as it can.
|
The default value (0) will perform redraws as fast as it can.
|
||||||
|
|
||||||
|
### OnSuspend
|
||||||
|
|
||||||
|
Name: OnSuspend
|
||||||
|
|
||||||
|
Type: func()
|
||||||
|
|
||||||
|
If set, this function will be called when windows initiates a switch to low power mode (suspend/hibernate)
|
||||||
|
|
||||||
|
### OnResume
|
||||||
|
|
||||||
|
Name: OnResume
|
||||||
|
|
||||||
|
Type: func()
|
||||||
|
|
||||||
|
If set, this function will be called when windows resumes from low power mode (suspend/hibernate)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Mac Specific Options
|
## Mac Specific Options
|
||||||
|
|
||||||
### TitleBar
|
### TitleBar
|
||||||
|
Loading…
Reference in New Issue
Block a user