fix: catch electron call bridge error
Signed-off-by: Innei <i@innei.in>
This commit is contained in:
@@ -230,6 +230,7 @@ export const createMainWindow = () => {
|
||||
cancelPollingUpdateUnreadCount()
|
||||
|
||||
const caller = callWindowExpose(window)
|
||||
|
||||
caller.onWindowShow()
|
||||
})
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { registerGlobalContext } from "@follow/shared/bridge"
|
||||
import { env } from "@follow/shared/env"
|
||||
import { authConfigManager } from "@hono/auth-js/react"
|
||||
import { repository } from "@pkg"
|
||||
@@ -11,6 +12,7 @@ import { isElectronBuild } from "~/constants"
|
||||
import { browserDB } from "~/database"
|
||||
import { initI18n } from "~/i18n"
|
||||
import { settingSyncQueue } from "~/modules/settings/helper/sync-queue"
|
||||
import { ElectronCloseEvent, ElectronShowEvent } from "~/providers/invalidate-query-provider"
|
||||
import { CleanerService } from "~/services/cleaner"
|
||||
|
||||
import { subscribeNetworkStatus } from "../atoms/network"
|
||||
@@ -54,6 +56,19 @@ export const initializeApp = async () => {
|
||||
// Set Environment
|
||||
document.documentElement.dataset.buildType = isElectronBuild ? "electron" : "web"
|
||||
|
||||
// Register global context for electron
|
||||
registerGlobalContext({
|
||||
/**
|
||||
* Electron app only
|
||||
*/
|
||||
onWindowClose() {
|
||||
document.dispatchEvent(new ElectronCloseEvent())
|
||||
},
|
||||
onWindowShow() {
|
||||
document.dispatchEvent(new ElectronShowEvent())
|
||||
},
|
||||
})
|
||||
|
||||
apm("migration", doMigration)
|
||||
|
||||
// Initialize dayjs
|
||||
|
||||
@@ -10,7 +10,6 @@ import { useModalStack } from "~/components/ui/modal"
|
||||
import { FeedForm } from "~/modules/discover/feed-form"
|
||||
import { usePresentUserProfileModal } from "~/modules/profile/hooks"
|
||||
|
||||
import { ElectronCloseEvent, ElectronShowEvent } from "./invalidate-query-provider"
|
||||
|
||||
export const ExtensionExposeProvider = () => {
|
||||
const { present } = useModalStack()
|
||||
@@ -19,15 +18,6 @@ export const ExtensionExposeProvider = () => {
|
||||
showSetting: (path) => window.router.showSettings(path),
|
||||
getGeneralSettings,
|
||||
getUISettings,
|
||||
/**
|
||||
* Electron app only
|
||||
*/
|
||||
onWindowClose() {
|
||||
document.dispatchEvent(new ElectronCloseEvent())
|
||||
},
|
||||
onWindowShow() {
|
||||
document.dispatchEvent(new ElectronShowEvent())
|
||||
},
|
||||
|
||||
toast,
|
||||
getApiUrl() {
|
||||
|
||||
@@ -45,12 +45,16 @@ function createProxy<T extends RenderGlobalContext>(window: BrowserWindow, path:
|
||||
|
||||
return createProxy(window, newPath)
|
||||
},
|
||||
apply(_, __, args: any[]) {
|
||||
async apply(_, __, args: any[]) {
|
||||
const methodPath = path.join(".")
|
||||
|
||||
return window.webContents.executeJavaScript(
|
||||
`globalThis.${PREFIX}.${methodPath}(${args.map((arg) => JSON.stringify(arg)).join(",")})`,
|
||||
)
|
||||
try {
|
||||
return await window.webContents.executeJavaScript(
|
||||
`globalThis.${PREFIX}?.${methodPath}?.(${args.map((arg) => JSON.stringify(arg)).join(",")})`,
|
||||
)
|
||||
} catch (err) {
|
||||
console.error(`Failed to executeJavaScript: ${methodPath}`, err)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user