Skip to content

Commit d8f010b

Browse files
committed
fix: verify window is hiddined before call
1 parent 8398e40 commit d8f010b

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
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: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,28 +292,54 @@ export function registerIpcEvents() {
292292
try {
293293
Log.info('[WARMUP] Starting silent echo test to warm up audio devices...')
294294

295+
const window = PhoneIslandController.instance.window.getWindow()
296+
if (!window) {
297+
Log.error('[WARMUP] Window not found, aborting warm-up')
298+
return
299+
}
300+
295301
// Hide the PhoneIsland window to prevent it from showing during warm-up
296302
PhoneIslandController.instance.forceHide()
297303

298304
// Mute the PhoneIsland window audio
299305
PhoneIslandController.instance.muteAudio()
300306

301-
// Wait a bit to ensure mute and hide are applied
302-
await new Promise(resolve => setTimeout(resolve, 550))
307+
// Wait and verify that hide and mute are actually applied
308+
// Use polling to ensure they're effective even on slow/loaded systems
309+
let attempts = 0
310+
const maxAttempts = 20 // Max 2 seconds (20 * 100ms)
311+
312+
while (attempts < maxAttempts) {
313+
await new Promise(resolve => setTimeout(resolve, 100))
314+
315+
const isHidden = !window.isVisible()
316+
const isMuted = window.webContents?.audioMuted
317+
318+
if (isHidden && isMuted) {
319+
Log.info(`[WARMUP] Window hidden and audio muted verified after ${attempts * 100}ms`)
320+
break
321+
}
322+
323+
if (attempts === maxAttempts - 1) {
324+
Log.warning(`[WARMUP] Could not verify hide/mute after ${maxAttempts * 100}ms (hidden: ${isHidden}, muted: ${isMuted})`)
325+
}
326+
327+
attempts++
328+
}
303329

304330
// Start echo test call to *43
305331
Log.info('[WARMUP] Starting call to *43')
306332
PhoneIslandController.instance.call('*43')
307333

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

311337
// End the call
312338
Log.info('[WARMUP] Ending echo test call')
313339
PhoneIslandController.instance.window.emit(IPC_EVENTS.END_CALL)
314340

315341
// Wait a bit before unmuting and showing
316-
await new Promise(resolve => setTimeout(resolve, 550))
342+
await new Promise(resolve => setTimeout(resolve, 500))
317343

318344
// Unmute the PhoneIsland window audio
319345
PhoneIslandController.instance.unmuteAudio()

0 commit comments

Comments
 (0)