fix(stage-tamagotchi): do not create nested callback for injeca constructor
Close #810
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import type { BrowserWindow } from 'electron'
|
||||
|
||||
import { env, platform } from 'node:process'
|
||||
|
||||
import { electronApp, optimizer } from '@electron-toolkit/utils'
|
||||
@@ -77,6 +79,12 @@ app.whenReady().then(async () => {
|
||||
|
||||
// BeatSync will create a background window to capture and process audio.
|
||||
const beatSync = injeca.provide('windows:beat-sync', () => setupBeatSync())
|
||||
const beatSyncDispatchTo = injeca.provide('windows:beat-sync:dispatch-to', {
|
||||
dependsOn: { beatSync },
|
||||
build: async ({ dependsOn }) => (window: BrowserWindow) => {
|
||||
return dependsOn.beatSync.dispatchTo(window)
|
||||
},
|
||||
})
|
||||
|
||||
const chatWindow = injeca.provide('windows:chat', {
|
||||
dependsOn: { widgetsManager },
|
||||
@@ -84,22 +92,16 @@ app.whenReady().then(async () => {
|
||||
})
|
||||
|
||||
const settingsWindow = injeca.provide('windows:settings', {
|
||||
dependsOn: { widgetsManager, beatSync },
|
||||
build: async ({ dependsOn }) => async () => {
|
||||
const { beatSync: _, ...setupArgs } = dependsOn
|
||||
const window = await setupSettingsWindowReusableFunc(setupArgs)()
|
||||
dependsOn.beatSync.dispatchTo(window)
|
||||
return window
|
||||
dependsOn: { widgetsManager, beatSync, beatSyncDispatchTo },
|
||||
build: async ({ dependsOn }) => {
|
||||
return setupSettingsWindowReusableFunc({ ...dependsOn, onWindowCreated: window => dependsOn.beatSyncDispatchTo(window) })
|
||||
},
|
||||
})
|
||||
|
||||
const mainWindow = injeca.provide('windows:main', {
|
||||
dependsOn: { settingsWindow, chatWindow, widgetsManager, noticeWindow, beatSync },
|
||||
dependsOn: { settingsWindow, chatWindow, widgetsManager, noticeWindow, beatSync, beatSyncDispatchTo },
|
||||
build: async ({ dependsOn }) => {
|
||||
const { beatSync: _, ...setupArgs } = dependsOn
|
||||
const window = await setupMainWindow(setupArgs)
|
||||
dependsOn.beatSync.dispatchTo(window)
|
||||
return window
|
||||
return setupMainWindow({ ...dependsOn, onWindowCreated: window => dependsOn.beatSyncDispatchTo(window) })
|
||||
},
|
||||
})
|
||||
|
||||
@@ -109,11 +111,8 @@ app.whenReady().then(async () => {
|
||||
})
|
||||
|
||||
const tray = injeca.provide('app:tray', {
|
||||
dependsOn: { mainWindow, settingsWindow, captionWindow, widgetsWindow: widgetsManager, beatSync, aboutWindow },
|
||||
build: async ({ dependsOn }) => {
|
||||
const { beatSync, aboutWindow, ...setupArgs } = dependsOn
|
||||
return setupTray({ ...setupArgs, beatSyncBgWindow: beatSync.window, aboutWindow })
|
||||
},
|
||||
dependsOn: { mainWindow, settingsWindow, captionWindow, widgetsWindow: widgetsManager, beatSyncBgWindow: beatSync, aboutWindow },
|
||||
build: async ({ dependsOn }) => setupTray(dependsOn),
|
||||
})
|
||||
|
||||
injeca.invoke({
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { BrowserWindow } from 'electron'
|
||||
|
||||
import type { setupBeatSync } from '../windows/beat-sync'
|
||||
import type { setupCaptionWindowManager } from '../windows/caption'
|
||||
import type { WidgetsWindowManager } from '../windows/widgets'
|
||||
|
||||
@@ -22,7 +23,7 @@ export function setupTray(params: {
|
||||
settingsWindow: () => Promise<BrowserWindow>
|
||||
captionWindow: ReturnType<typeof setupCaptionWindowManager>
|
||||
widgetsWindow: WidgetsWindowManager
|
||||
beatSyncBgWindow: BrowserWindow
|
||||
beatSyncBgWindow: Awaited<ReturnType<typeof setupBeatSync>>
|
||||
aboutWindow: () => Promise<BrowserWindow>
|
||||
}): void {
|
||||
once(() => {
|
||||
@@ -53,7 +54,7 @@ export function setupTray(params: {
|
||||
...is.dev || env.MAIN_APP_DEBUG || env.APP_DEBUG
|
||||
? [
|
||||
{ type: 'header', label: 'DevTools' },
|
||||
{ label: 'Troubleshoot BeatSync...', click: () => params.beatSyncBgWindow.webContents.openDevTools() },
|
||||
{ label: 'Troubleshoot BeatSync...', click: () => params.beatSyncBgWindow.window.webContents.openDevTools() },
|
||||
{ type: 'separator' },
|
||||
] as const // :(
|
||||
: [],
|
||||
|
||||
@@ -33,6 +33,7 @@ export async function setupMainWindow(params: {
|
||||
chatWindow: () => Promise<BrowserWindow>
|
||||
widgetsManager: WidgetsWindowManager
|
||||
noticeWindow: NoticeWindowManager
|
||||
onWindowCreated?: (window: BrowserWindow) => void
|
||||
}) {
|
||||
const {
|
||||
setup: setupConfig,
|
||||
@@ -64,6 +65,10 @@ export async function setupMainWindow(params: {
|
||||
...transparentWindowConfig(),
|
||||
})
|
||||
|
||||
if (params.onWindowCreated) {
|
||||
params.onWindowCreated(window)
|
||||
}
|
||||
|
||||
// NOTICE: in development mode, open devtools by default
|
||||
if (is.dev || env.MAIN_APP_DEBUG || env.APP_DEBUG) {
|
||||
try {
|
||||
|
||||
@@ -12,6 +12,7 @@ import { setupSettingsWindowInvokes } from './rpc/index.electron'
|
||||
|
||||
export function setupSettingsWindowReusableFunc(params: {
|
||||
widgetsManager: WidgetsWindowManager
|
||||
onWindowCreated?: (window: BrowserWindow) => void
|
||||
}) {
|
||||
return createReusableWindow(async () => {
|
||||
const window = new BrowserWindow({
|
||||
@@ -26,6 +27,10 @@ export function setupSettingsWindowReusableFunc(params: {
|
||||
},
|
||||
})
|
||||
|
||||
if (params.onWindowCreated) {
|
||||
params.onWindowCreated(window)
|
||||
}
|
||||
|
||||
window.on('ready-to-show', () => window.show())
|
||||
window.webContents.setWindowOpenHandler((details) => {
|
||||
shell.openExternal(details.url)
|
||||
|
||||
Reference in New Issue
Block a user