Skip to content

Commit

Permalink
style: prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Wurielle authored and actions-user committed Jan 18, 2025
1 parent c5b39a9 commit 7c6c640
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 66 deletions.
55 changes: 30 additions & 25 deletions apps/app/src/electron/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { createApp, h } from 'vue'
import { createPinia } from 'pinia'
import createTray from '@/teams/tray/electron-tray'
import ElectronWindowManager from '@/modules/electron-window-manager'
import { createMessengerGameOverlayWindow, createMessengerWindow } from '@/teams/messenger/electron/background'
import {
createMessengerGameOverlayWindow,
createMessengerWindow,
} from '@/teams/messenger/electron/background'
import { createSpeechWorkerWindow } from '@/teams/speech-worker/electron/background'
import { bridgeModules } from '@/electron/bridge'
import registerElectronStartup from '@/modules/electron-startup/register'
Expand All @@ -27,25 +30,26 @@ const App = () => {
const createWindows = () =>
app
.whenReady()
.then(async () => Promise.all([
ElectronWindowManager.registerInstance(
'messenger',
createMessengerWindow,
),
ElectronWindowManager.registerInstance(
'overlay',
createOverlayWindow,
),
ElectronWindowManager.registerInstance(
'speech-worker',
createSpeechWorkerWindow,
),
ElectronWindowManager.registerInstance(
'messenger-game-overlay',
createMessengerGameOverlayWindow,
),
]))

.then(async () =>
Promise.all([
ElectronWindowManager.registerInstance(
'messenger',
createMessengerWindow,
),
ElectronWindowManager.registerInstance(
'overlay',
createOverlayWindow,
),
ElectronWindowManager.registerInstance(
'speech-worker',
createSpeechWorkerWindow,
),
ElectronWindowManager.registerInstance(
'messenger-game-overlay',
createMessengerGameOverlayWindow,
),
]),
)

const registerElectronPinia = () => {
createApp(h({})).use(
Expand All @@ -54,9 +58,7 @@ const App = () => {
}

const startGameOverlay = async () =>
app.whenReady().then(() =>
gameOverlay.start(),
)
app.whenReady().then(() => gameOverlay.start())

const startAppServer = async () =>
app.whenReady().then(async () =>
Expand Down Expand Up @@ -89,7 +91,7 @@ const App = () => {
}

function exec(description: string, action: () => any) {
console.log(`[app]: ${ description }`)
console.log(`[app]: ${description}`)
return action()
}

Expand Down Expand Up @@ -164,7 +166,10 @@ const App = () => {

app.on('web-contents-created', (_, webContents) => {
webContents.on('preload-error', (_, preloadPath, error) => {
console.error(`Preload script error:\nPath: ${ preloadPath }\nError:`, error)
console.error(
`Preload script error:\nPath: ${preloadPath}\nError:`,
error,
)
})
})
}
Expand Down
100 changes: 64 additions & 36 deletions apps/app/src/electron/game-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class GameOverlay {
private markQuit = false
private scaleFactor = 1.0

constructor() {
}
constructor() {}

public isReady = () => ready.promise

Expand Down Expand Up @@ -89,12 +88,12 @@ class GameOverlay {
const { top, left, right, bottom } = this.WinControl.getByPid(
payload.pid,
).getDimensions()
const width = right-left
const height = bottom-top
const width = right - left
const height = bottom - top

mouse.getPosition().then(async (initialPosition) => {
await mouse.setPosition(
new Point(left+width / 2, top+height / 2),
new Point(left + width / 2, top + height / 2),
)
await mouse.leftClick()
await mouse.setPosition(initialPosition)
Expand Down Expand Up @@ -254,9 +253,7 @@ class GameOverlay {
public injectByProcess(processInfo: ProcessInfo) {
for (const window of this.Overlay.getTopWindows()) {
if (window.processId === processInfo.pid) {
console.log(
`[game-overlay] Injecting ${ JSON.stringify(window) }`,
)
console.log(`[game-overlay] Injecting ${JSON.stringify(window)}`)
this.Overlay.injectProcess(window)
this.hookedProcesses.push(processInfo)
}
Expand All @@ -267,7 +264,11 @@ class GameOverlay {
const databasesStore = useDatabasesStore()
const gameOverlayStore = useGameOverlayStore()
/* Importing win-control in preload breaks reload so we import it dynamically on start instead */
return Promise.all([import('@packages/electron-game-overlay'), import('win-control'), gameOverlayStore.$whenReady()]).then(([Overlay, WinControl]) => {
return Promise.all([
import('@packages/electron-game-overlay'),
import('win-control'),
gameOverlayStore.$whenReady(),
]).then(([Overlay, WinControl]) => {
this.WinControl = WinControl
this.Overlay = Overlay.default
this.scaleFactor = screen.getDisplayNearestPoint({
Expand All @@ -277,35 +278,62 @@ class GameOverlay {

this.startOverlay()


watch(() => [gameOverlayStore.enableGameOverlay, gameOverlayStore.allowlist, gameOverlayStore.denylist, databasesStore.data], () => {
if (!gameOverlayStore.enableGameOverlay) return
console.log('[game-overlay] Creating process watcher process')
const child = fork(path.join(EXTERNALS_DIR, 'detect-game.js'))
child.on('message', (processInfo: ProcessEvent) => {
if (processInfo.type === 'process-creation') {
const { filepath } = processInfo.payload
const isGame = micromatch.isMatch(filepath, [...gameOverlayStore.allowlist, ...(databasesStore.data['game-overlay-allowlist'] || [])].filter(Boolean))
&& !micromatch.isMatch(filepath, [...gameOverlayStore.denylist, ...(databasesStore.data['game-overlay-denylist'] || [])].filter(Boolean))
if (isGame) {
console.log('[game-overlay]: Game launched', filepath)
// require('windows-tlist').getProcessInfo(processInfo.payload.pid).then(({ modules }: any) => console.log(modules.map(({ path }: any) => path.substring(path.lastIndexOf('\\')+1))))
this.injectByProcessOnceFocused(processInfo.payload)
watch(
() => [
gameOverlayStore.enableGameOverlay,
gameOverlayStore.allowlist,
gameOverlayStore.denylist,
databasesStore.data,
],
() => {
if (!gameOverlayStore.enableGameOverlay) return
console.log('[game-overlay] Creating process watcher process')
const child = fork(path.join(EXTERNALS_DIR, 'detect-game.js'))
child.on('message', (processInfo: ProcessEvent) => {
if (processInfo.type === 'process-creation') {
const { filepath } = processInfo.payload
const isGame =
micromatch.isMatch(
filepath,
[
...gameOverlayStore.allowlist,
...(databasesStore.data['game-overlay-allowlist'] || []),
].filter(Boolean),
) &&
!micromatch.isMatch(
filepath,
[
...gameOverlayStore.denylist,
...(databasesStore.data['game-overlay-denylist'] || []),
].filter(Boolean),
)
if (isGame) {
console.log('[game-overlay]: Game launched', filepath)
// require('windows-tlist').getProcessInfo(processInfo.payload.pid).then(({ modules }: any) => console.log(modules.map(({ path }: any) => path.substring(path.lastIndexOf('\\')+1))))
this.injectByProcessOnceFocused(processInfo.payload)
}
}
}
if (processInfo.type === 'process-deletion') {
if (this.hookedProcesses.find((process) => process.pid === processInfo.payload.pid)) {
this.hookedProcesses = this.hookedProcesses.filter((process) => process.pid !== processInfo.payload.pid)
if (processInfo.type === 'process-deletion') {
if (
this.hookedProcesses.find(
(process) => process.pid === processInfo.payload.pid,
)
) {
this.hookedProcesses = this.hookedProcesses.filter(
(process) => process.pid !== processInfo.payload.pid,
)
}
}
}
})
onWatcherCleanup(() => {
child.kill()
})
}, {
deep: true,
immediate: true,
})
})
onWatcherCleanup(() => {
child.kill()
})
},
{
deep: true,
immediate: true,
},
)

onIPCGameOverlayStartIntercept(() => {
this.startIntercept()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { mouse } from '@/modules/node-mouse'
import throttle from 'lodash/throttle'
import { Hitbox } from '@/modules/vue-hitboxes/types'
import { BrowserWindow, screen, shell } from 'electron'
import { useMessengerStore, useMessengerWindowStore } from '@/teams/messenger/store'
import {
useMessengerStore,
useMessengerWindowStore,
} from '@/teams/messenger/store'
import { useSettingsStore } from '@/features/settings/store'
import { useHitboxesStore } from '@/modules/vue-hitboxes/hitboxes.store'
import { Deferred } from '@packages/toolbox'
Expand Down Expand Up @@ -184,9 +187,9 @@ export const ElectronMessengerWindow = () => {
.filter(({ w, h }) => w && h)
.some(({ x, y, w, h }: Hitbox) => {
const isWithinXHitbox =
mouseX >= windowX+x && mouseX <= windowX+x+w
mouseX >= windowX + x && mouseX <= windowX + x + w
const isWithinYHitbox =
mouseY >= windowY+y && mouseY <= windowY+y+h
mouseY >= windowY + y && mouseY <= windowY + y + h
return isWithinXHitbox && isWithinYHitbox
})
if (isWithinAnyHitboxes) {
Expand All @@ -200,7 +203,9 @@ export const ElectronMessengerWindow = () => {

const toggleWindow = throttle((context: 'mouse' | 'keyboard') => {
const foregroundWindowPid = WinControl?.getForeground()?.getPid()
const hookedProcess = gameOverlay.hookedProcesses.find((process) => process.pid === foregroundWindowPid)
const hookedProcess = gameOverlay.hookedProcesses.find(
(process) => process.pid === foregroundWindowPid,
)
if (hookedProcess && !gameOverlay.intercepting) {
gameOverlay.startIntercept()
return
Expand Down Expand Up @@ -293,7 +298,7 @@ export const ElectronMessengerWindow = () => {
setDisplay(localSettingsStore.display)
})
ready.resolve(window)
import('win-control').then((module) => WinControl = module)
import('win-control').then((module) => (WinControl = module))
}

isReady().then(() => {
Expand Down

0 comments on commit 7c6c640

Please sign in to comment.