Skip to content

Commit c2a09dd

Browse files
authored
fixed Win11 phantom Alt Tabs + fullscreen fix + set mouse events support (#65)
* fix: properly cleanup resources on macOS quit to prevent hanging * added save screenshot handler * fixed screenshot code, there needs to be a little delay before deleting the file otherwise steam fails to copy it * WIP trying to fix window bug * WIP * Made the implementation I had much simpler * removed unneeded change * reverted some changes * disabled disable-direct-composition and enabled fullscreenable * Added support for set ignore mouse events
1 parent 002f052 commit c2a09dd

2 files changed

Lines changed: 92 additions & 23 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {Object} json
3+
* @param {string} json.correlationId
4+
* @param {string} json.url
5+
* @param {{ ignore: boolean, forward?: boolean }} json.body
6+
* @param {import('ws').WebSocket} ws
7+
* @param {import('electron').BrowserWindow} mainWindow
8+
*/
9+
export default async (json, ws, mainWindow) => {
10+
const { ignore, forward } = json.body
11+
12+
mainWindow.setIgnoreMouseEvents(ignore, { forward })
13+
14+
const result = {
15+
correlationId: json.correlationId,
16+
url: json.url,
17+
body: {
18+
success: true
19+
}
20+
}
21+
ws.send(JSON.stringify(result))
22+
}

assets/electron/template/app/src/index.js

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import windowSetY from './handlers/window/set-y.js'
4848
import windowShowDevTools from './handlers/window/show-dev-tools.js'
4949
import windowUnmaximize from './handlers/window/unmaximize.js'
5050
import windowSetFullscreen from './handlers/window/set-fullscreen.js'
51+
import windowSetIgnoreMouseEvents from './handlers/window/set-ignore-mouse-events.js'
5152

5253
// dialog
5354
import dialogFolder from './handlers/dialog/folder.js'
@@ -276,7 +277,7 @@ let client
276277
console.log('config.enableSteamSupport', config.enableSteamSupport)
277278
if (config.enableSteamSupport) {
278279
app.commandLine.appendSwitch('in-process-gpu')
279-
app.commandLine.appendSwitch('disable-direct-composition')
280+
//app.commandLine.appendSwitch('disable-direct-composition')
280281
app.commandLine.appendSwitch('no-sandbox')
281282

282283
// const isNecessary = steamworks.restartAppIfNecessary(config.steamGameId)
@@ -332,6 +333,11 @@ let wss = null
332333
*/
333334
let isQuitting = false
334335

336+
/**
337+
* @type {Promise<void> | null}
338+
*/
339+
let cleanupPromise = null
340+
335341
/**
336342
* @param {string} message
337343
*/
@@ -490,6 +496,9 @@ const createAppServer = (mainWindow, serveStatic = true) => {
490496
case '/window/set-fullscreen':
491497
await windowSetFullscreen(json, ws, mainWindow)
492498
break
499+
case '/window/set-ignore-mouse-events':
500+
await windowSetIgnoreMouseEvents(json, ws, mainWindow)
501+
break
493502
case '/engine':
494503
await engine(json, ws)
495504
break
@@ -622,6 +631,7 @@ const createWindow = async () => {
622631
width: config.width,
623632
height: config.height,
624633
fullscreen: config.fullscreen,
634+
fullscreenable: true,
625635
frame: config.frame,
626636
transparent: config.transparent,
627637
alwaysOnTop: config.alwaysOnTop,
@@ -718,11 +728,14 @@ const createWindow = async () => {
718728
/**
719729
* Cleanup all resources before quitting
720730
*/
721-
const cleanup = () => {
722-
return new Promise((resolve) => {
731+
const cleanup = async () => {
732+
if (cleanupPromise) {
733+
return cleanupPromise
734+
}
735+
736+
cleanupPromise = (async () => {
723737
console.log('Cleaning up resources...')
724738

725-
// Close all WebSocket clients
726739
for (const client of clients) {
727740
try {
728741
client.close()
@@ -732,7 +745,6 @@ const cleanup = () => {
732745
}
733746
clients.clear()
734747

735-
// Close WebSocket server
736748
if (wss) {
737749
try {
738750
wss.close()
@@ -742,19 +754,54 @@ const cleanup = () => {
742754
wss = null
743755
}
744756

745-
// Close HTTP server
757+
if (rpc) {
758+
try {
759+
await rpc.clearActivity()
760+
} catch (e) {
761+
console.error('Error clearing Discord RPC activity:', e)
762+
}
763+
764+
try {
765+
rpc.destroy()
766+
} catch (e) {
767+
console.error('Error destroying Discord RPC client:', e)
768+
}
769+
770+
rpc = undefined
771+
}
772+
773+
try {
774+
protocol.unhandle('app')
775+
} catch (e) {
776+
console.error('Error unregistering app protocol:', e)
777+
}
778+
746779
if (httpServer) {
747-
httpServer.close(() => {
748-
console.log('HTTP server closed')
749-
httpServer = null
750-
resolve()
780+
const server = httpServer
781+
httpServer = null
782+
783+
await new Promise((resolve) => {
784+
let isSettled = false
785+
const done = () => {
786+
if (!isSettled) {
787+
isSettled = true
788+
resolve()
789+
}
790+
}
791+
792+
server.close(() => {
793+
console.log('HTTP server closed')
794+
done()
795+
})
796+
797+
setTimeout(done, 500)
751798
})
752-
// Force resolve after timeout in case server doesn't close cleanly
753-
setTimeout(resolve, 500)
754-
} else {
755-
resolve()
756799
}
800+
})().finally(() => {
801+
cleanupPromise = null
757802
})
803+
804+
return cleanupPromise
758805
}
759806

760807
const registerHandlers = async () => {
@@ -877,21 +924,21 @@ app.on('before-quit', (event) => {
877924
if (!isQuitting) {
878925
event.preventDefault()
879926
isQuitting = true
880-
cleanup().then(() => {
881-
app.quit()
882-
})
927+
cleanup()
928+
.catch((error) => {
929+
console.error('Error while quitting application:', error)
930+
})
931+
.finally(() => {
932+
app.quit()
933+
})
883934
}
884935
})
885936

886937
app.on('will-quit', () => {
887-
// Final cleanup - synchronous operations only
888-
// Close any remaining WebSocket clients
889938
for (const client of clients) {
890939
try {
891-
client.terminate() // Force close
892-
} catch (e) {
893-
// Ignore errors during final cleanup
894-
}
940+
client.terminate()
941+
} catch (e) {}
895942
}
896943
clients.clear()
897944
})

0 commit comments

Comments
 (0)