Skip to content

Commit

Permalink
fix: 完善盒盖状态插拔电源动作
Browse files Browse the repository at this point in the history
盒盖状态,插拔电源,能分别做盒盖动作

Log:
pms: TASK-371973
  • Loading branch information
ECQZXC committed Jan 20, 2025
1 parent d18396e commit 5f6f794
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
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

0 comments on commit 5f6f794

Please sign in to comment.