mirror of
https://github.com/viarotel-org/escrcpy.git
synced 2024-11-30 18:24:27 +01:00
perf: ⬆️ Optimize edge hiding performance
This commit is contained in:
parent
14a81de211
commit
74a91a4058
@ -38,6 +38,9 @@ export class Edger {
|
|||||||
this.handleWindowBlur = this.handleWindowBlur.bind(this)
|
this.handleWindowBlur = this.handleWindowBlur.bind(this)
|
||||||
this.handleWindowFocus = this.handleWindowFocus.bind(this)
|
this.handleWindowFocus = this.handleWindowFocus.bind(this)
|
||||||
|
|
||||||
|
// Add mouse tracking timer reference
|
||||||
|
this.mouseTrackingTimer = null
|
||||||
|
|
||||||
this.initialize()
|
this.initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,8 +107,9 @@ export class Edger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
showWindow() {
|
showWindow() {
|
||||||
if (!this.isHidden || this.isAnimating)
|
if (!this.window || this.window.isDestroyed() || !this.isHidden || this.isAnimating)
|
||||||
return
|
return
|
||||||
|
|
||||||
clearTimeout(this.hideDebounceTimer)
|
clearTimeout(this.hideDebounceTimer)
|
||||||
|
|
||||||
if (this.showDebounceTimer)
|
if (this.showDebounceTimer)
|
||||||
@ -119,8 +123,9 @@ export class Edger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hideWindow() {
|
hideWindow() {
|
||||||
if (this.isHidden || this.isAnimating)
|
if (!this.window || this.window.isDestroyed() || this.isHidden || this.isAnimating)
|
||||||
return
|
return
|
||||||
|
|
||||||
clearTimeout(this.showDebounceTimer)
|
clearTimeout(this.showDebounceTimer)
|
||||||
|
|
||||||
if (this.hideDebounceTimer)
|
if (this.hideDebounceTimer)
|
||||||
@ -166,6 +171,11 @@ export class Edger {
|
|||||||
if (this.window.isAlwaysOnTop()) {
|
if (this.window.isAlwaysOnTop()) {
|
||||||
this.wasAlwaysOnTop = true
|
this.wasAlwaysOnTop = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add window close event listener
|
||||||
|
this.window.on('closed', () => {
|
||||||
|
this.destroy()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleWindowBlur() {
|
handleWindowBlur() {
|
||||||
@ -182,7 +192,9 @@ export class Edger {
|
|||||||
|
|
||||||
setAlwaysOnTop(value) {
|
setAlwaysOnTop(value) {
|
||||||
try {
|
try {
|
||||||
// 某些系统上可能需要特定的参数
|
if (!this.window || this.window.isDestroyed())
|
||||||
|
return
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
this.window.setAlwaysOnTop(value, 'floating')
|
this.window.setAlwaysOnTop(value, 'floating')
|
||||||
}
|
}
|
||||||
@ -263,32 +275,45 @@ export class Edger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
|
// Clear all timers
|
||||||
this.cleanupAnimation()
|
this.cleanupAnimation()
|
||||||
if (this.showDebounceTimer) {
|
if (this.showDebounceTimer) {
|
||||||
clearTimeout(this.showDebounceTimer)
|
clearTimeout(this.showDebounceTimer)
|
||||||
|
this.showDebounceTimer = null
|
||||||
}
|
}
|
||||||
if (this.hideDebounceTimer) {
|
if (this.hideDebounceTimer) {
|
||||||
clearTimeout(this.hideDebounceTimer)
|
clearTimeout(this.hideDebounceTimer)
|
||||||
|
this.hideDebounceTimer = null
|
||||||
|
}
|
||||||
|
if (this.mouseTrackingTimer) {
|
||||||
|
clearInterval(this.mouseTrackingTimer)
|
||||||
|
this.mouseTrackingTimer = null
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清理事件监听
|
// Clean up event listeners
|
||||||
if (this.window) {
|
if (this.window && !this.window.isDestroyed()) {
|
||||||
this.window.removeListener('blur', this.handleWindowBlur)
|
this.window.removeListener('blur', this.handleWindowBlur)
|
||||||
this.window.removeListener('focus', this.handleWindowFocus)
|
this.window.removeListener('focus', this.handleWindowFocus)
|
||||||
this.window.removeAllListeners()
|
this.window.removeAllListeners()
|
||||||
|
|
||||||
// 恢复原始置顶状态
|
// Restore original always on top state
|
||||||
if (this.window.isAlwaysOnTop() !== this.wasAlwaysOnTop) {
|
if (this.window.isAlwaysOnTop() !== this.wasAlwaysOnTop) {
|
||||||
this.setAlwaysOnTop(this.wasAlwaysOnTop)
|
this.setAlwaysOnTop(this.wasAlwaysOnTop)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mouseMovementBuffer = []
|
this.mouseMovementBuffer = []
|
||||||
|
this.window = null
|
||||||
|
this.dockEdge = null
|
||||||
|
this.originalBounds = null
|
||||||
|
this.isHidden = false
|
||||||
|
this.isDragging = false
|
||||||
|
this.isAnimating = false
|
||||||
}
|
}
|
||||||
|
|
||||||
startMouseTracking() {
|
startMouseTracking() {
|
||||||
const trackMouse = () => {
|
const trackMouse = () => {
|
||||||
if (!this.dockEdge)
|
if (!this.dockEdge || !this.window || this.window.isDestroyed())
|
||||||
return
|
return
|
||||||
|
|
||||||
const currentTime = Date.now()
|
const currentTime = Date.now()
|
||||||
@ -297,6 +322,7 @@ export class Edger {
|
|||||||
// Update mouse movement buffer
|
// Update mouse movement buffer
|
||||||
this.updateMouseBuffer(mousePos, currentTime)
|
this.updateMouseBuffer(mousePos, currentTime)
|
||||||
|
|
||||||
|
try {
|
||||||
const windowBounds = this.window.getBounds()
|
const windowBounds = this.window.getBounds()
|
||||||
const display = screen.getDisplayNearestPoint(mousePos)
|
const display = screen.getDisplayNearestPoint(mousePos)
|
||||||
const screenBounds = display.workArea
|
const screenBounds = display.workArea
|
||||||
@ -313,8 +339,13 @@ export class Edger {
|
|||||||
|
|
||||||
this.lastMousePosition = mousePos
|
this.lastMousePosition = mousePos
|
||||||
}
|
}
|
||||||
|
catch (err) {
|
||||||
|
// Window was destroyed, clean up
|
||||||
|
this.destroy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setInterval(trackMouse, 16)
|
this.mouseTrackingTimer = setInterval(trackMouse, 16)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateMouseBuffer(mousePos, currentTime) {
|
updateMouseBuffer(mousePos, currentTime) {
|
||||||
|
Loading…
Reference in New Issue
Block a user