Skip to content

Commit 7c6c640

Browse files
Wurielleactions-user
authored andcommitted
style: prettier formatting
1 parent c5b39a9 commit 7c6c640

File tree

3 files changed

+104
-66
lines changed

3 files changed

+104
-66
lines changed

apps/app/src/electron/app.ts

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import { createApp, h } from 'vue'
77
import { createPinia } from 'pinia'
88
import createTray from '@/teams/tray/electron-tray'
99
import ElectronWindowManager from '@/modules/electron-window-manager'
10-
import { createMessengerGameOverlayWindow, createMessengerWindow } from '@/teams/messenger/electron/background'
10+
import {
11+
createMessengerGameOverlayWindow,
12+
createMessengerWindow,
13+
} from '@/teams/messenger/electron/background'
1114
import { createSpeechWorkerWindow } from '@/teams/speech-worker/electron/background'
1215
import { bridgeModules } from '@/electron/bridge'
1316
import registerElectronStartup from '@/modules/electron-startup/register'
@@ -27,25 +30,26 @@ const App = () => {
2730
const createWindows = () =>
2831
app
2932
.whenReady()
30-
.then(async () => Promise.all([
31-
ElectronWindowManager.registerInstance(
32-
'messenger',
33-
createMessengerWindow,
34-
),
35-
ElectronWindowManager.registerInstance(
36-
'overlay',
37-
createOverlayWindow,
38-
),
39-
ElectronWindowManager.registerInstance(
40-
'speech-worker',
41-
createSpeechWorkerWindow,
42-
),
43-
ElectronWindowManager.registerInstance(
44-
'messenger-game-overlay',
45-
createMessengerGameOverlayWindow,
46-
),
47-
]))
48-
33+
.then(async () =>
34+
Promise.all([
35+
ElectronWindowManager.registerInstance(
36+
'messenger',
37+
createMessengerWindow,
38+
),
39+
ElectronWindowManager.registerInstance(
40+
'overlay',
41+
createOverlayWindow,
42+
),
43+
ElectronWindowManager.registerInstance(
44+
'speech-worker',
45+
createSpeechWorkerWindow,
46+
),
47+
ElectronWindowManager.registerInstance(
48+
'messenger-game-overlay',
49+
createMessengerGameOverlayWindow,
50+
),
51+
]),
52+
)
4953

5054
const registerElectronPinia = () => {
5155
createApp(h({})).use(
@@ -54,9 +58,7 @@ const App = () => {
5458
}
5559

5660
const startGameOverlay = async () =>
57-
app.whenReady().then(() =>
58-
gameOverlay.start(),
59-
)
61+
app.whenReady().then(() => gameOverlay.start())
6062

6163
const startAppServer = async () =>
6264
app.whenReady().then(async () =>
@@ -89,7 +91,7 @@ const App = () => {
8991
}
9092

9193
function exec(description: string, action: () => any) {
92-
console.log(`[app]: ${ description }`)
94+
console.log(`[app]: ${description}`)
9395
return action()
9496
}
9597

@@ -164,7 +166,10 @@ const App = () => {
164166

165167
app.on('web-contents-created', (_, webContents) => {
166168
webContents.on('preload-error', (_, preloadPath, error) => {
167-
console.error(`Preload script error:\nPath: ${ preloadPath }\nError:`, error)
169+
console.error(
170+
`Preload script error:\nPath: ${preloadPath}\nError:`,
171+
error,
172+
)
168173
})
169174
})
170175
}

apps/app/src/electron/game-overlay.ts

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ class GameOverlay {
3737
private markQuit = false
3838
private scaleFactor = 1.0
3939

40-
constructor() {
41-
}
40+
constructor() {}
4241

4342
public isReady = () => ready.promise
4443

@@ -89,12 +88,12 @@ class GameOverlay {
8988
const { top, left, right, bottom } = this.WinControl.getByPid(
9089
payload.pid,
9190
).getDimensions()
92-
const width = right-left
93-
const height = bottom-top
91+
const width = right - left
92+
const height = bottom - top
9493

9594
mouse.getPosition().then(async (initialPosition) => {
9695
await mouse.setPosition(
97-
new Point(left+width / 2, top+height / 2),
96+
new Point(left + width / 2, top + height / 2),
9897
)
9998
await mouse.leftClick()
10099
await mouse.setPosition(initialPosition)
@@ -254,9 +253,7 @@ class GameOverlay {
254253
public injectByProcess(processInfo: ProcessInfo) {
255254
for (const window of this.Overlay.getTopWindows()) {
256255
if (window.processId === processInfo.pid) {
257-
console.log(
258-
`[game-overlay] Injecting ${ JSON.stringify(window) }`,
259-
)
256+
console.log(`[game-overlay] Injecting ${JSON.stringify(window)}`)
260257
this.Overlay.injectProcess(window)
261258
this.hookedProcesses.push(processInfo)
262259
}
@@ -267,7 +264,11 @@ class GameOverlay {
267264
const databasesStore = useDatabasesStore()
268265
const gameOverlayStore = useGameOverlayStore()
269266
/* Importing win-control in preload breaks reload so we import it dynamically on start instead */
270-
return Promise.all([import('@packages/electron-game-overlay'), import('win-control'), gameOverlayStore.$whenReady()]).then(([Overlay, WinControl]) => {
267+
return Promise.all([
268+
import('@packages/electron-game-overlay'),
269+
import('win-control'),
270+
gameOverlayStore.$whenReady(),
271+
]).then(([Overlay, WinControl]) => {
271272
this.WinControl = WinControl
272273
this.Overlay = Overlay.default
273274
this.scaleFactor = screen.getDisplayNearestPoint({
@@ -277,35 +278,62 @@ class GameOverlay {
277278

278279
this.startOverlay()
279280

280-
281-
watch(() => [gameOverlayStore.enableGameOverlay, gameOverlayStore.allowlist, gameOverlayStore.denylist, databasesStore.data], () => {
282-
if (!gameOverlayStore.enableGameOverlay) return
283-
console.log('[game-overlay] Creating process watcher process')
284-
const child = fork(path.join(EXTERNALS_DIR, 'detect-game.js'))
285-
child.on('message', (processInfo: ProcessEvent) => {
286-
if (processInfo.type === 'process-creation') {
287-
const { filepath } = processInfo.payload
288-
const isGame = micromatch.isMatch(filepath, [...gameOverlayStore.allowlist, ...(databasesStore.data['game-overlay-allowlist'] || [])].filter(Boolean))
289-
&& !micromatch.isMatch(filepath, [...gameOverlayStore.denylist, ...(databasesStore.data['game-overlay-denylist'] || [])].filter(Boolean))
290-
if (isGame) {
291-
console.log('[game-overlay]: Game launched', filepath)
292-
// require('windows-tlist').getProcessInfo(processInfo.payload.pid).then(({ modules }: any) => console.log(modules.map(({ path }: any) => path.substring(path.lastIndexOf('\\')+1))))
293-
this.injectByProcessOnceFocused(processInfo.payload)
281+
watch(
282+
() => [
283+
gameOverlayStore.enableGameOverlay,
284+
gameOverlayStore.allowlist,
285+
gameOverlayStore.denylist,
286+
databasesStore.data,
287+
],
288+
() => {
289+
if (!gameOverlayStore.enableGameOverlay) return
290+
console.log('[game-overlay] Creating process watcher process')
291+
const child = fork(path.join(EXTERNALS_DIR, 'detect-game.js'))
292+
child.on('message', (processInfo: ProcessEvent) => {
293+
if (processInfo.type === 'process-creation') {
294+
const { filepath } = processInfo.payload
295+
const isGame =
296+
micromatch.isMatch(
297+
filepath,
298+
[
299+
...gameOverlayStore.allowlist,
300+
...(databasesStore.data['game-overlay-allowlist'] || []),
301+
].filter(Boolean),
302+
) &&
303+
!micromatch.isMatch(
304+
filepath,
305+
[
306+
...gameOverlayStore.denylist,
307+
...(databasesStore.data['game-overlay-denylist'] || []),
308+
].filter(Boolean),
309+
)
310+
if (isGame) {
311+
console.log('[game-overlay]: Game launched', filepath)
312+
// require('windows-tlist').getProcessInfo(processInfo.payload.pid).then(({ modules }: any) => console.log(modules.map(({ path }: any) => path.substring(path.lastIndexOf('\\')+1))))
313+
this.injectByProcessOnceFocused(processInfo.payload)
314+
}
294315
}
295-
}
296-
if (processInfo.type === 'process-deletion') {
297-
if (this.hookedProcesses.find((process) => process.pid === processInfo.payload.pid)) {
298-
this.hookedProcesses = this.hookedProcesses.filter((process) => process.pid !== processInfo.payload.pid)
316+
if (processInfo.type === 'process-deletion') {
317+
if (
318+
this.hookedProcesses.find(
319+
(process) => process.pid === processInfo.payload.pid,
320+
)
321+
) {
322+
this.hookedProcesses = this.hookedProcesses.filter(
323+
(process) => process.pid !== processInfo.payload.pid,
324+
)
325+
}
299326
}
300-
}
301-
})
302-
onWatcherCleanup(() => {
303-
child.kill()
304-
})
305-
}, {
306-
deep: true,
307-
immediate: true,
308-
})
327+
})
328+
onWatcherCleanup(() => {
329+
child.kill()
330+
})
331+
},
332+
{
333+
deep: true,
334+
immediate: true,
335+
},
336+
)
309337

310338
onIPCGameOverlayStartIntercept(() => {
311339
this.startIntercept()

apps/app/src/teams/messenger/modules/electron-messenger-window/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { mouse } from '@/modules/node-mouse'
33
import throttle from 'lodash/throttle'
44
import { Hitbox } from '@/modules/vue-hitboxes/types'
55
import { BrowserWindow, screen, shell } from 'electron'
6-
import { useMessengerStore, useMessengerWindowStore } from '@/teams/messenger/store'
6+
import {
7+
useMessengerStore,
8+
useMessengerWindowStore,
9+
} from '@/teams/messenger/store'
710
import { useSettingsStore } from '@/features/settings/store'
811
import { useHitboxesStore } from '@/modules/vue-hitboxes/hitboxes.store'
912
import { Deferred } from '@packages/toolbox'
@@ -184,9 +187,9 @@ export const ElectronMessengerWindow = () => {
184187
.filter(({ w, h }) => w && h)
185188
.some(({ x, y, w, h }: Hitbox) => {
186189
const isWithinXHitbox =
187-
mouseX >= windowX+x && mouseX <= windowX+x+w
190+
mouseX >= windowX + x && mouseX <= windowX + x + w
188191
const isWithinYHitbox =
189-
mouseY >= windowY+y && mouseY <= windowY+y+h
192+
mouseY >= windowY + y && mouseY <= windowY + y + h
190193
return isWithinXHitbox && isWithinYHitbox
191194
})
192195
if (isWithinAnyHitboxes) {
@@ -200,7 +203,9 @@ export const ElectronMessengerWindow = () => {
200203

201204
const toggleWindow = throttle((context: 'mouse' | 'keyboard') => {
202205
const foregroundWindowPid = WinControl?.getForeground()?.getPid()
203-
const hookedProcess = gameOverlay.hookedProcesses.find((process) => process.pid === foregroundWindowPid)
206+
const hookedProcess = gameOverlay.hookedProcesses.find(
207+
(process) => process.pid === foregroundWindowPid,
208+
)
204209
if (hookedProcess && !gameOverlay.intercepting) {
205210
gameOverlay.startIntercept()
206211
return
@@ -293,7 +298,7 @@ export const ElectronMessengerWindow = () => {
293298
setDisplay(localSettingsStore.display)
294299
})
295300
ready.resolve(window)
296-
import('win-control').then((module) => WinControl = module)
301+
import('win-control').then((module) => (WinControl = module))
297302
}
298303

299304
isReady().then(() => {

0 commit comments

Comments
 (0)