Skip to content

Commit

Permalink
perf: 🚀 Update to scrcpy v3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Nov 25, 2024
1 parent 14a81de commit bf06382
Show file tree
Hide file tree
Showing 38 changed files with 1,726 additions and 25 deletions.
8 changes: 4 additions & 4 deletions electron/configs/scrcpy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export const getScrcpyPath = () => {
switch (process.platform) {
case 'win32':
return extraResolve('win/scrcpy/scrcpy.exe')
// case 'darwin':
// return extraResolve(`mac-${process.arch}/scrcpy/scrcpy`)
// case 'linux':
// return extraResolve('linux/scrcpy/scrcpy')
case 'darwin':
return extraResolve(`mac/scrcpy/scrcpy`)
case 'linux':
return extraResolve('linux/scrcpy/scrcpy')
default:
return which.sync('scrcpy', { nothrow: true })
}
Expand Down
73 changes: 52 additions & 21 deletions electron/helpers/edger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class Edger {
this.handleWindowBlur = this.handleWindowBlur.bind(this)
this.handleWindowFocus = this.handleWindowFocus.bind(this)

// Add mouse tracking timer reference
this.mouseTrackingTimer = null

this.initialize()
}

Expand Down Expand Up @@ -104,8 +107,9 @@ export class Edger {
}

showWindow() {
if (!this.isHidden || this.isAnimating)
if (!this.window || this.window.isDestroyed() || !this.isHidden || this.isAnimating)
return

clearTimeout(this.hideDebounceTimer)

if (this.showDebounceTimer)
Expand All @@ -119,8 +123,9 @@ export class Edger {
}

hideWindow() {
if (this.isHidden || this.isAnimating)
if (!this.window || this.window.isDestroyed() || this.isHidden || this.isAnimating)
return

clearTimeout(this.showDebounceTimer)

if (this.hideDebounceTimer)
Expand Down Expand Up @@ -166,6 +171,11 @@ export class Edger {
if (this.window.isAlwaysOnTop()) {
this.wasAlwaysOnTop = true
}

// Add window close event listener
this.window.on('closed', () => {
this.destroy()
})
}

handleWindowBlur() {
Expand All @@ -182,7 +192,9 @@ export class Edger {

setAlwaysOnTop(value) {
try {
// 某些系统上可能需要特定的参数
if (!this.window || this.window.isDestroyed())
return

if (process.platform === 'darwin') {
this.window.setAlwaysOnTop(value, 'floating')
}
Expand Down Expand Up @@ -263,32 +275,45 @@ export class Edger {
}

destroy() {
// Clear all timers
this.cleanupAnimation()
if (this.showDebounceTimer) {
clearTimeout(this.showDebounceTimer)
this.showDebounceTimer = null
}
if (this.hideDebounceTimer) {
clearTimeout(this.hideDebounceTimer)
this.hideDebounceTimer = null
}
if (this.mouseTrackingTimer) {
clearInterval(this.mouseTrackingTimer)
this.mouseTrackingTimer = null
}

// 清理事件监听
if (this.window) {
// Clean up event listeners
if (this.window && !this.window.isDestroyed()) {
this.window.removeListener('blur', this.handleWindowBlur)
this.window.removeListener('focus', this.handleWindowFocus)
this.window.removeAllListeners()

// 恢复原始置顶状态
// Restore original always on top state
if (this.window.isAlwaysOnTop() !== this.wasAlwaysOnTop) {
this.setAlwaysOnTop(this.wasAlwaysOnTop)
}
}

this.mouseMovementBuffer = []
this.window = null
this.dockEdge = null
this.originalBounds = null
this.isHidden = false
this.isDragging = false
this.isAnimating = false
}

startMouseTracking() {
const trackMouse = () => {
if (!this.dockEdge)
if (!this.dockEdge || !this.window || this.window.isDestroyed())
return

const currentTime = Date.now()
Expand All @@ -297,24 +322,30 @@ export class Edger {
// Update mouse movement buffer
this.updateMouseBuffer(mousePos, currentTime)

const windowBounds = this.window.getBounds()
const display = screen.getDisplayNearestPoint(mousePos)
const screenBounds = display.workArea

// Check that the mouse is stable
if (this.isMouseStable()) {
if (this.isMouseNearEdge(mousePos, windowBounds, screenBounds)) {
this.showWindow()
}
else if (this.isMouseOutsideWindow(mousePos, windowBounds)) {
this.hideWindow()
try {
const windowBounds = this.window.getBounds()
const display = screen.getDisplayNearestPoint(mousePos)
const screenBounds = display.workArea

// Check that the mouse is stable
if (this.isMouseStable()) {
if (this.isMouseNearEdge(mousePos, windowBounds, screenBounds)) {
this.showWindow()
}
else if (this.isMouseOutsideWindow(mousePos, windowBounds)) {
this.hideWindow()
}
}
}

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) {
Expand Down
6 changes: 6 additions & 0 deletions electron/resources/extra/linux/scrcpy/scrcpy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
cd "$(dirname ${BASH_SOURCE[0]})"
export ADB="${ADB:-./adb}"
export SCRCPY_SERVER_PATH="${SCRCPY_SERVER_PATH:-./scrcpy-server}"
export SCRCPY_ICON_PATH="${SCRCPY_ICON_PATH:-./icon.png}"
./scrcpy_bin "$@"
Binary file not shown.
Loading

0 comments on commit bf06382

Please sign in to comment.