fix(stage-tamagotchi): not found issue
This commit is contained in:
@@ -16,11 +16,13 @@ import macOSTrayIcon from '../../resources/tray-icon-macos.png?asset'
|
||||
|
||||
import { openDebugger, setupDebugger } from './app/debugger'
|
||||
import { emitAppBeforeQuit, emitAppReady, emitAppWindowAllClosed, onAppBeforeQuit } from './libs/bootkit/lifecycle'
|
||||
import { setElectronMainDirname } from './libs/electron/location'
|
||||
import { setupInlayWindow } from './windows/inlay'
|
||||
import { setupMainWindow } from './windows/main'
|
||||
import { setupSettingsWindow } from './windows/settings'
|
||||
import { toggleWindowShow } from './windows/shared/window'
|
||||
|
||||
setElectronMainDirname(__dirname)
|
||||
setGlobalFormat(Format.Pretty)
|
||||
setGlobalLogLevel(LogLevel.Log)
|
||||
setupDebugger()
|
||||
|
||||
@@ -5,6 +5,16 @@ import { env } from 'node:process'
|
||||
|
||||
import { is } from '@electron-toolkit/utils'
|
||||
|
||||
let electronMainDirname: string = ''
|
||||
|
||||
export function setElectronMainDirname(dirname: string) {
|
||||
electronMainDirname = dirname
|
||||
}
|
||||
|
||||
export function getElectronMainDirname() {
|
||||
return electronMainDirname
|
||||
}
|
||||
|
||||
export function baseUrl(parentOfIndexHtml: string) {
|
||||
if (is.dev && env.ELECTRON_RENDERER_URL) {
|
||||
return { url: env.ELECTRON_RENDERER_URL }
|
||||
|
||||
@@ -3,22 +3,25 @@ import type { BrowserWindowConstructorOptions, Rectangle } from 'electron'
|
||||
import { dirname, join, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
import { is } from '@electron-toolkit/utils'
|
||||
import { defu } from 'defu'
|
||||
import { BrowserWindow, shell } from 'electron'
|
||||
import { isMacOS } from 'std-env'
|
||||
|
||||
import icon from '../../../../resources/icon.png?asset'
|
||||
|
||||
import { baseUrl, load } from '../../libs/electron/location'
|
||||
import { baseUrl, getElectronMainDirname, load } from '../../libs/electron/location'
|
||||
import { transparentWindowConfig } from '../shared'
|
||||
import { createConfig } from '../shared/persistence'
|
||||
import { setupAppInvokeHandlers } from './rpc/index.electron'
|
||||
import { setupMainWindowElectronInvokes } from './rpc/index.electron'
|
||||
|
||||
interface AppConfig {
|
||||
windows?: Array<Pick<BrowserWindowConstructorOptions, 'title' | 'x' | 'y' | 'width' | 'height'> & { tag: string }>
|
||||
}
|
||||
|
||||
export async function setupMainWindow() {
|
||||
export async function setupMainWindow(params: {
|
||||
settingsWindow: () => Promise<BrowserWindow>
|
||||
}) {
|
||||
const {
|
||||
setup: setupConfig,
|
||||
get: getConfig,
|
||||
@@ -44,6 +47,16 @@ export async function setupMainWindow() {
|
||||
...transparentWindowConfig(),
|
||||
})
|
||||
|
||||
// NOTICE: in development mode, open devtools by default
|
||||
if (is.dev) {
|
||||
try {
|
||||
window.webContents.openDevTools()
|
||||
}
|
||||
catch (err) {
|
||||
console.error('failed to open devtools:', err)
|
||||
}
|
||||
}
|
||||
|
||||
function handleNewBounds(newBounds: Rectangle) {
|
||||
const config = getConfig()!
|
||||
if (!config.windows || !Array.isArray(config.windows)) {
|
||||
@@ -90,9 +103,9 @@ export async function setupMainWindow() {
|
||||
return { action: 'deny' }
|
||||
})
|
||||
|
||||
await load(window, baseUrl(resolve(import.meta.dirname, '..', '..', '..', 'renderer')))
|
||||
await load(window, baseUrl(resolve(getElectronMainDirname(), '..', 'renderer')))
|
||||
|
||||
setupAppInvokeHandlers(window)
|
||||
setupMainWindowElectronInvokes({ window, settingsWindow: params.settingsWindow })
|
||||
|
||||
return window
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { dirname, join, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { join, resolve } from 'node:path'
|
||||
|
||||
import { BrowserWindow, shell } from 'electron'
|
||||
|
||||
import icon from '../../../../resources/icon.png?asset'
|
||||
|
||||
import { baseUrl, load, withHashRoute } from '../../libs/electron/location'
|
||||
import { baseUrl, getElectronMainDirname, load, withHashRoute } from '../../libs/electron/location'
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
export async function setupSettingsWindow() {
|
||||
export function setupSettingsWindowReusableFunc() {
|
||||
const window = new BrowserWindow({
|
||||
title: 'Settings',
|
||||
width: 600.0,
|
||||
@@ -28,7 +25,7 @@ export async function setupSettingsWindow() {
|
||||
return { action: 'deny' }
|
||||
})
|
||||
|
||||
await load(window, withHashRoute(baseUrl(resolve(__dirname, '..', '..', '..', 'renderer')), '/settings'))
|
||||
await load(window, withHashRoute(baseUrl(resolve(getElectronMainDirname(), '..', 'renderer')), '/settings'))
|
||||
|
||||
return window
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user