feat: invalid main window query from add window
This commit is contained in:
parent
4be62e6666
commit
9d63c7d255
|
|
@ -23,6 +23,10 @@ if (process.defaultApp) {
|
|||
|
||||
app.dock.setIcon(path.join(__dirname, "../../resources/icon.png"))
|
||||
|
||||
let mainWindow: BrowserWindow
|
||||
|
||||
export const getMainWindow = () => mainWindow
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
|
|
@ -37,7 +41,6 @@ app.whenReady().then(() => {
|
|||
optimizer.watchWindowShortcuts(window)
|
||||
})
|
||||
|
||||
let mainWindow: BrowserWindow
|
||||
mainWindow = createWindow()
|
||||
|
||||
app.on("activate", () => {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
export type RendererHandlers = {
|
||||
invalidateQuery: (key: (string | number | undefined)[]) => void
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
import { tipc } from "@egoist/tipc/main"
|
||||
import { tipc, getRendererHandlers } from "@egoist/tipc/main"
|
||||
import type { MessageBoxOptions } from "electron"
|
||||
import { dialog, Menu, ShareMenu } from "electron"
|
||||
import { RendererHandlers } from "./renderer-handlers"
|
||||
import { getMainWindow } from "."
|
||||
|
||||
const t = tipc.create()
|
||||
|
||||
|
|
@ -93,6 +95,14 @@ export const router = {
|
|||
return null
|
||||
}
|
||||
}),
|
||||
|
||||
invalidateQuery: t.procedure
|
||||
.input<(string | number | undefined)[]>()
|
||||
.action(async ({ input }) => {
|
||||
const mainWindow = getMainWindow()
|
||||
const handlers = getRendererHandlers<RendererHandlers>(mainWindow.webContents)
|
||||
handlers.invalidateQuery.send(input)
|
||||
}),
|
||||
}
|
||||
|
||||
export type Router = typeof router
|
||||
|
|
|
|||
|
|
@ -1,9 +1,25 @@
|
|||
import { Outlet } from "react-router-dom"
|
||||
|
||||
import { useDark } from "./hooks/useDark"
|
||||
import { handlers } from "./tipc"
|
||||
import { useEffect } from "react"
|
||||
|
||||
import { queryClient } from "@renderer/lib/query-client"
|
||||
|
||||
|
||||
function App() {
|
||||
useDark()
|
||||
|
||||
useEffect(() => {
|
||||
const unlisten = handlers?.invalidateQuery.listen((queryKey) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey,
|
||||
})
|
||||
})
|
||||
|
||||
return unlisten
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import { useEffect } from "react";
|
|||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
import { Card, CardHeader } from "@renderer/components/ui/card";
|
||||
import { client } from "@renderer/lib/client";
|
||||
|
||||
const formSchema = z.object({
|
||||
view: z.string(),
|
||||
|
|
@ -82,8 +83,14 @@ export function Component() {
|
|||
variables.view !== `${feed.data?.subscription?.view}`
|
||||
) {
|
||||
Queries.subscription.byView(feed.data?.subscription?.view).invalidate();
|
||||
client?.invalidateQuery(
|
||||
Queries.subscription.byView(feed.data?.subscription?.view).key
|
||||
);
|
||||
}
|
||||
Queries.subscription.byView(Number.parseInt(variables.view)).invalidate();
|
||||
client?.invalidateQuery(Queries.subscription.byView(Number.parseInt(variables.view)).key);
|
||||
Queries.feed.byId({ id: feed.data?.feed.id }).invalidate();
|
||||
client?.invalidateQuery(Queries.feed.byId({ id: feed.data?.feed.id }).key);
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import { entries } from "./entries"
|
||||
import { subscription } from "./subscriptions"
|
||||
import { feed } from "./feed"
|
||||
|
||||
export const Queries = {
|
||||
subscription,
|
||||
entries,
|
||||
feed,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
import { createEventHandlers } from "@egoist/tipc/renderer"
|
||||
import { RendererHandlers } from "@main/renderer-handlers"
|
||||
|
||||
export const handlers = window.electron ? createEventHandlers<RendererHandlers>({
|
||||
on: (channel, callback) => {
|
||||
const remover = window.electron!.ipcRenderer.on(channel, callback)
|
||||
return () => {
|
||||
remover()
|
||||
}
|
||||
},
|
||||
|
||||
send: window.electron!.ipcRenderer.send,
|
||||
}) : null
|
||||
Loading…
Reference in New Issue