Skip to content

Commit 7c44609

Browse files
committed
fix: verify window is hidden before call
1 parent 8398e40 commit 7c44609

File tree

3 files changed

+82
-18
lines changed

3 files changed

+82
-18
lines changed

src/main/classes/controllers/PhoneIslandController.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ export class PhoneIslandController {
3030
//make sure the size is equal to [0,0] when you want to close the phone island, otherwise the size will not close and will generate slowness problems.
3131
if (h === 0 && w === 0) {
3232
window.hide()
33+
} else if (this.isWarmingUp) {
34+
// During warm-up: force hide even if size changes
35+
Log.info(`[RESIZE] FORCING HIDE during warm-up (size: ${w}x${h}, visible: ${window.isVisible()})`)
36+
window.hide()
3337
} else {
34-
// Don't show window during warm-up
35-
if (!window.isVisible() && !this.isWarmingUp) {
38+
// Normal flow: show if not visible (no logging)
39+
if (!window.isVisible()) {
3640
window.show()
3741
window.setAlwaysOnTop(true)
3842
}
@@ -49,6 +53,12 @@ export class PhoneIslandController {
4953
const window = this.window.getWindow()
5054
if (window) {
5155

56+
// Block showPhoneIsland during warm-up
57+
if (this.isWarmingUp) {
58+
Log.info(`[SHOW_PHONE_ISLAND] BLOCKED during warm-up (size: ${size.w}x${size.h})`)
59+
return
60+
}
61+
5262
this.resize(size)
5363
if (process.platform !== 'linux') {
5464
const phoneIslandPosition = AccountController.instance.getAccountPhoneIslandPosition()
@@ -178,9 +188,10 @@ export class PhoneIslandController {
178188
try {
179189
const window = this.window.getWindow()
180190
if (window) {
191+
const wasVisible = window.isVisible()
181192
this.isWarmingUp = true
182193
window.hide()
183-
Log.info('PhoneIsland window hidden')
194+
Log.info(`[FORCE_HIDE] PhoneIsland window hidden (was visible: ${wasVisible}, isWarmingUp now: ${this.isWarmingUp})`)
184195
}
185196
} catch (e) {
186197
Log.warning('error during force hiding PhoneIsland:', e)
@@ -194,10 +205,13 @@ export class PhoneIslandController {
194205
this.isWarmingUp = false
195206
// Only show if there's actually content (size > 0)
196207
const bounds = window.getBounds()
208+
Log.info(`[FORCE_SHOW] Attempting to show (isWarmingUp now: ${this.isWarmingUp}, bounds: ${bounds.width}x${bounds.height})`)
197209
if (bounds.width > 0 && bounds.height > 0) {
198210
window.show()
199211
window.setAlwaysOnTop(true)
200-
Log.info('PhoneIsland window shown')
212+
Log.info('[FORCE_SHOW] PhoneIsland window shown')
213+
} else {
214+
Log.info('[FORCE_SHOW] Not showing - no content (size is 0)')
201215
}
202216
}
203217
} catch (e) {

src/main/lib/ipcEvents.ts

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -280,40 +280,79 @@ export function registerIpcEvents() {
280280

281281
// Handler for warm-up audio devices request from renderer
282282
ipcMain.on(IPC_EVENTS.WARMUP_AUDIO_DEVICES, async () => {
283-
// Check if warm-up has already been executed
284-
if (hasRunAudioWarmup) {
285-
Log.info('[WARMUP] Audio warm-up already executed, skipping...')
286-
return
287-
}
283+
try {
284+
Log.info('[WARMUP] Warm-up request received (hasRunAudioWarmup:', hasRunAudioWarmup, ')')
285+
286+
// Check if warm-up has already been executed
287+
if (hasRunAudioWarmup) {
288+
Log.info('[WARMUP] Audio warm-up already executed, skipping...')
289+
return
290+
}
288291

289-
// Mark as executed
290-
hasRunAudioWarmup = true
292+
// Mark as executed
293+
hasRunAudioWarmup = true
291294

292-
try {
293295
Log.info('[WARMUP] Starting silent echo test to warm up audio devices...')
294296

297+
if (!PhoneIslandController.instance) {
298+
Log.error('[WARMUP] PhoneIslandController.instance not found, aborting warm-up')
299+
return
300+
}
301+
302+
const window = PhoneIslandController.instance.window.getWindow()
303+
if (!window) {
304+
Log.error('[WARMUP] Window not found, aborting warm-up')
305+
return
306+
}
307+
308+
Log.info('[WARMUP] Window state BEFORE hide:', {
309+
exists: !!window,
310+
isVisible: window.isVisible(),
311+
isMuted: window.webContents?.audioMuted
312+
})
313+
295314
// Hide the PhoneIsland window to prevent it from showing during warm-up
296315
PhoneIslandController.instance.forceHide()
297316

298317
// Mute the PhoneIsland window audio
299318
PhoneIslandController.instance.muteAudio()
300319

301-
// Wait a bit to ensure mute and hide are applied
302-
await new Promise(resolve => setTimeout(resolve, 550))
320+
// Wait and verify that hide and mute are actually applied
321+
// Use polling to ensure they're effective even on slow/loaded systems
322+
let attempts = 0
323+
const maxAttempts = 20 // Max 2 seconds (20 * 100ms)
324+
325+
while (attempts < maxAttempts) {
326+
await new Promise(resolve => setTimeout(resolve, 100))
327+
328+
const isHidden = !window.isVisible()
329+
const isMuted = window.webContents?.audioMuted
330+
331+
if (isHidden && isMuted) {
332+
Log.info(`[WARMUP] Window hidden and audio muted verified after ${attempts * 100}ms`)
333+
break
334+
}
335+
336+
if (attempts === maxAttempts - 1) {
337+
Log.warning(`[WARMUP] Could not verify hide/mute after ${maxAttempts * 100}ms (hidden: ${isHidden}, muted: ${isMuted})`)
338+
}
339+
340+
attempts++
341+
}
303342

304343
// Start echo test call to *43
305344
Log.info('[WARMUP] Starting call to *43')
306345
PhoneIslandController.instance.call('*43')
307346

308-
// Keep the call active for 5 seconds to warm up devices
347+
// Keep the call active for 1.5 seconds to warm up devices
309348
await new Promise(resolve => setTimeout(resolve, 1500))
310349

311350
// End the call
312351
Log.info('[WARMUP] Ending echo test call')
313352
PhoneIslandController.instance.window.emit(IPC_EVENTS.END_CALL)
314353

315354
// Wait a bit before unmuting and showing
316-
await new Promise(resolve => setTimeout(resolve, 550))
355+
await new Promise(resolve => setTimeout(resolve, 500))
317356

318357
// Unmute the PhoneIsland window audio
319358
PhoneIslandController.instance.unmuteAudio()
@@ -325,8 +364,12 @@ export function registerIpcEvents() {
325364
} catch (error) {
326365
Log.error('[WARMUP] Error during audio warm-up:', error)
327366
// Make sure to unmute and show even if there's an error
328-
PhoneIslandController.instance.unmuteAudio()
329-
PhoneIslandController.instance.forceShow()
367+
try {
368+
PhoneIslandController.instance?.unmuteAudio()
369+
PhoneIslandController.instance?.forceShow()
370+
} catch (cleanupError) {
371+
Log.error('[WARMUP] Error during cleanup:', cleanupError)
372+
}
330373
}
331374
})
332375

src/renderer/src/pages/PhoneIslandPage.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ export function PhoneIslandPage() {
7878
window.electron.receive(IPC_EVENTS.CHANGE_PREFERRED_DEVICES, (devices: PreferredDevices) => {
7979
Log.info('Received CHANGE_PREFERRED_DEVICES in PhoneIslandPage:', devices)
8080

81+
// Debug: log the check conditions
82+
Log.info('Warm-up check:', {
83+
hasRunWarmup: hasRunWarmup.current,
84+
platform: window.api?.platform,
85+
shouldRun: !hasRunWarmup.current && (window.api?.platform === 'win32' || window.api?.platform === 'darwin')
86+
})
87+
8188
// Run audio warm-up first, only once after PhoneIsland is fully initialized
8289
// Only on Windows/macOS where the issue occurs
8390
if (!hasRunWarmup.current && (window.api?.platform === 'win32' || window.api?.platform === 'darwin')) {

0 commit comments

Comments
 (0)