Skip to content

Commit 5f6f794

Browse files
committed
fix: 完善盒盖状态插拔电源动作
盒盖状态,插拔电源,能分别做盒盖动作 Log: pms: TASK-371973
1 parent d18396e commit 5f6f794

3 files changed

Lines changed: 36 additions & 20 deletions

File tree

session/power1/lid_switch.go

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,39 +89,33 @@ func (h *LidSwitchHandler) doLidStateChanged(state bool) {
8989
h.isLidOpenLast = state
9090

9191
m := h.manager
92-
m.setPrepareSuspend(suspendStateLidClose)
93-
m.PropsMu.Lock()
94-
m.lidSwitchState = lidSwitchStateClose
95-
m.PropsMu.Unlock()
96-
m.claimOrReleaseAmbientLight()
9792

9893
// 合盖
9994
if !state {
100-
var onBattery bool
101-
onBattery = h.manager.OnBattery
95+
m.setPrepareSuspend(suspendStateLidClose)
96+
m.PropsMu.Lock()
97+
m.lidSwitchState = lidSwitchStateClose
98+
m.PropsMu.Unlock()
99+
m.claimOrReleaseAmbientLight()
100+
102101
var lidCloseAction int32
103-
if onBattery {
102+
if m.OnBattery {
104103
lidCloseAction = m.BatteryLidClosedAction.Get() // 获取合盖操作
105104
} else {
106105
lidCloseAction = m.LinePowerLidClosedAction.Get() // 获取合盖操作
107106
}
108-
switch lidCloseAction {
109-
case powerActionShutdown:
110-
m.doShutdown()
111-
case powerActionSuspend:
112-
m.doSuspendByFront()
113-
case powerActionHibernate:
114-
m.doHibernateByFront()
115-
case powerActionTurnOffScreen:
116-
m.doTurnOffScreen()
117-
case powerActionDoNothing:
118-
return
119-
}
107+
m.doLidClosedAction(lidCloseAction)
120108

121109
if lidCloseAction != powerActionTurnOffScreen && !m.isWmBlackScreenActive() {
122110
m.setWmBlackScreenActive(true)
123111
}
124112
} else { // 开盖
113+
m.setPrepareSuspend(suspendStateLidOpen)
114+
m.PropsMu.Lock()
115+
m.lidSwitchState = lidSwitchStateOpen
116+
m.PropsMu.Unlock()
117+
m.claimOrReleaseAmbientLight()
118+
125119
err := h.stopAskUser()
126120
if err != nil {
127121
logger.Warning("stopAskUser error:", err)

session/power1/manager.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,18 @@ func (m *Manager) listenEventToHandleIdleOff() error {
527527

528528
return nil
529529
}
530+
531+
func (m *Manager) doLidClosedAction(action int32) {
532+
switch action {
533+
case powerActionShutdown:
534+
m.doShutdown()
535+
case powerActionSuspend:
536+
m.doSuspendByFront()
537+
case powerActionHibernate:
538+
m.doHibernateByFront()
539+
case powerActionTurnOffScreen:
540+
m.doTurnOffScreen()
541+
case powerActionDoNothing:
542+
return
543+
}
544+
}

session/power1/manager_events.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,20 @@ func (m *Manager) initOnBatteryChangedHandler() {
5353
logger.Debug("property OnBattery changed to", onBattery)
5454
m.PropsMu.Lock()
5555
changed := m.setPropOnBattery(onBattery)
56+
state := m.lidSwitchState
5657
m.PropsMu.Unlock()
5758

5859
if changed {
5960
if onBattery {
6061
playSound(soundutils.EventPowerUnplug)
62+
if state == lidSwitchStateClose {
63+
m.doLidClosedAction(m.BatteryLidClosedAction.Get())
64+
}
6165
} else {
6266
playSound(soundutils.EventPowerPlug)
67+
if state == lidSwitchStateClose {
68+
m.doLidClosedAction(m.LinePowerLidClosedAction.Get())
69+
}
6370
}
6471
}
6572
})

0 commit comments

Comments
 (0)