Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 完善盒盖状态插拔电源动作 #734

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions session/power1/lid_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,39 +89,33 @@ func (h *LidSwitchHandler) doLidStateChanged(state bool) {
h.isLidOpenLast = state

m := h.manager
m.setPrepareSuspend(suspendStateLidClose)
m.PropsMu.Lock()
m.lidSwitchState = lidSwitchStateClose
m.PropsMu.Unlock()
m.claimOrReleaseAmbientLight()

// 合盖
if !state {
var onBattery bool
onBattery = h.manager.OnBattery
m.setPrepareSuspend(suspendStateLidClose)
m.PropsMu.Lock()
m.lidSwitchState = lidSwitchStateClose
m.PropsMu.Unlock()
m.claimOrReleaseAmbientLight()

var lidCloseAction int32
if onBattery {
if m.OnBattery {
lidCloseAction = m.BatteryLidClosedAction.Get() // 获取合盖操作
} else {
lidCloseAction = m.LinePowerLidClosedAction.Get() // 获取合盖操作
}
switch lidCloseAction {
case powerActionShutdown:
m.doShutdown()
case powerActionSuspend:
m.doSuspendByFront()
case powerActionHibernate:
m.doHibernateByFront()
case powerActionTurnOffScreen:
m.doTurnOffScreen()
case powerActionDoNothing:
return
}
m.doLidClosedAction(lidCloseAction)

if lidCloseAction != powerActionTurnOffScreen && !m.isWmBlackScreenActive() {
m.setWmBlackScreenActive(true)
}
} else { // 开盖
m.setPrepareSuspend(suspendStateLidOpen)
m.PropsMu.Lock()
m.lidSwitchState = lidSwitchStateOpen
m.PropsMu.Unlock()
m.claimOrReleaseAmbientLight()

err := h.stopAskUser()
if err != nil {
logger.Warning("stopAskUser error:", err)
Expand Down
15 changes: 15 additions & 0 deletions session/power1/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,18 @@ func (m *Manager) listenEventToHandleIdleOff() error {

return nil
}

func (m *Manager) doLidClosedAction(action int32) {
switch action {
case powerActionShutdown:
m.doShutdown()
case powerActionSuspend:
m.doSuspendByFront()
case powerActionHibernate:
m.doHibernateByFront()
case powerActionTurnOffScreen:
m.doTurnOffScreen()
case powerActionDoNothing:
return
}
}
7 changes: 7 additions & 0 deletions session/power1/manager_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,20 @@ func (m *Manager) initOnBatteryChangedHandler() {
logger.Debug("property OnBattery changed to", onBattery)
m.PropsMu.Lock()
changed := m.setPropOnBattery(onBattery)
state := m.lidSwitchState
m.PropsMu.Unlock()

if changed {
if onBattery {
playSound(soundutils.EventPowerUnplug)
if state == lidSwitchStateClose {
m.doLidClosedAction(m.BatteryLidClosedAction.Get())
}
} else {
playSound(soundutils.EventPowerPlug)
if state == lidSwitchStateClose {
m.doLidClosedAction(m.LinePowerLidClosedAction.Get())
}
}
}
})
Expand Down
Loading