fix: optional window.electron

This commit is contained in:
DIYgod
2024-05-24 10:32:45 +08:00
parent 48db1f1a50
commit f3fafff1ed
6 changed files with 15 additions and 13 deletions
@@ -99,7 +99,7 @@ export function FeedCategory({
label: "Delete Category",
click: async () => {
if (
await client.showConfirmDialog({
await client?.showConfirmDialog({
title: `Delete Category ${data.name}?`,
message: `This operation will delete your category, but the feeds it contains will be retained and grouped by website.`,
options: {
+2 -2
View File
@@ -151,7 +151,7 @@ export const useEntryActions = ({
!entry.images?.length,
onClick: async () => {
if (!entry.url || !entry.images?.length) return
const response = await client.saveToEagle({
const response = await client?.saveToEagle({
url: entry.url,
images: entry.images,
})
@@ -174,7 +174,7 @@ export const useEntryActions = ({
action: "share",
onClick: () => {
if (!entry.url) return
client.showShareMenu(entry.url)
client?.showShareMenu(entry.url)
},
},
],
+5 -3
View File
@@ -1,6 +1,8 @@
import { createClient } from "@egoist/tipc/renderer"
import type { Router } from "@main/tipc"
export const client = createClient<Router>({
ipcInvoke: window.electron.ipcRenderer.invoke,
})
export const client = window.electron
? createClient<Router>({
ipcInvoke: window.electron.ipcRenderer.invoke,
})
: null
+5 -5
View File
@@ -17,7 +17,7 @@ export const showNativeMenu = async (
type: "text" as const,
label: "Inspect Element",
click: () => {
client.inspectElement({
client?.inspectElement({
x: e.pageX,
y: e.pageY,
})
@@ -33,21 +33,21 @@ export const showNativeMenu = async (
el.setAttribute("data-context-menu-open", "true")
}
const unlisten = window.electron.ipcRenderer.on("menu-click", (_, index) => {
const unlisten = window.electron?.ipcRenderer.on("menu-click", (_, index) => {
const item = items[index]
if (item && item.type === "text") {
item.click()
}
})
window.electron.ipcRenderer.once("menu-closed", () => {
unlisten()
window.electron?.ipcRenderer.once("menu-closed", () => {
unlisten?.()
if (el instanceof HTMLElement) {
el.removeAttribute("data-context-menu-open")
}
})
await client.showContextMenu({
await client?.showContextMenu({
items: items.map((item) => {
if (item.type === "text") {
return {
+1 -1
View File
@@ -1,7 +1,7 @@
import Versions from "../components/Versions"
export function Component() {
const ipcHandle = (): void => window.electron.ipcRenderer.send("ping")
const ipcHandle = (): void => window.electron?.ipcRenderer.send("ping")
return (
<>