Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import { subscribe } from "@/lib/tauriEvent";
import { SearchIcon } from "lucide-react";
import { call } from "@/control";
import { useRequests } from "./useRequests";
Expand Down Expand Up @@ -396,9 +396,9 @@ function Shell({ first }: { first: boolean }) {
void invoke("import_link_closed")
.catch(() => {})
.then(take);
const un = listen("import-link", () => void take());
const un = subscribe("import-link", () => void take());
return () => {
void un.then((f) => f());
un();
};
}, []);
const closeImport = useCallback(() => {
Expand Down Expand Up @@ -435,15 +435,15 @@ function Shell({ first }: { first: boolean }) {
void invoke<string | null>("take_pending_view")
.then(go)
.catch(() => {});
const un = listen<string>("open-view", (e) => {
const un = subscribe<string>("open-view", (e) => {
go(e.payload);
void invoke("take_pending_view").catch(() => {});
});
// 连接那一层(切换器里的「管理连接…」)要落页时发的
const local = (e: Event) => go((e as CustomEvent<string>).detail);
window.addEventListener("tw-open-view", local);
return () => {
void un.then((f) => f());
un();
window.removeEventListener("tw-open-view", local);
};
}, []);
Expand Down Expand Up @@ -526,7 +526,7 @@ function Shell({ first }: { first: boolean }) {
*/
useEffect(() => {
let alive = true;
const un = listen<string>("core-state", (e) => {
const un = subscribe<string>("core-state", (e) => {
if (!alive) return;
setCore(e.payload);
// 又起来了:之前读状态失败的次数和原因作废,这一回重新数
Expand All @@ -535,7 +535,7 @@ function Shell({ first }: { first: boolean }) {
setLinkError(null);
}
});
void un
void un.ready
.then(() => invoke<string>("core_state"))
.then((c) => {
if (alive) setCore(c);
Expand All @@ -545,7 +545,7 @@ function Shell({ first }: { first: boolean }) {
});
return () => {
alive = false;
void un.then((f) => f());
un();
};
}, []);

Expand Down
10 changes: 5 additions & 5 deletions src/Notices.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useRef, useState } from "react";
import { BellIcon, XIcon } from "lucide-react";
import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import { subscribe } from "@/lib/tauriEvent";
import { Button } from "@/ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "@/ui/popover";
import { when } from "@/format";
Expand Down Expand Up @@ -62,8 +62,8 @@ export function Notices({

useEffect(() => {
load();
const un = listen<Notice[]>("notices-changed", (e) => setList(e.payload));
return () => void un.then((f) => f());
const un = subscribe<Notice[]>("notices-changed", (e) => setList(e.payload));
return un;
}, [load]);

useEffect(() => {
Expand All @@ -74,8 +74,8 @@ export function Notices({
invoke<NoticeMode>("notice_mode")
.then(setMode)
.catch(() => setMode("system"));
const un = listen<NoticeMode>("notice-mode-changed", (e) => setMode(e.payload));
return () => void un.then((f) => f());
const un = subscribe<NoticeMode>("notice-mode-changed", (e) => setMode(e.payload));
return un;
}, []);

function markRead(key: string) {
Expand Down
6 changes: 3 additions & 3 deletions src/RequestDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
import { listen } from "@tauri-apps/api/event";
import { subscribe } from "@/lib/tauriEvent";
import { call } from "@/control";
import { useText } from "@/i18n";
import { coreText } from "@/i18n/core.i18n";
Expand Down Expand Up @@ -154,7 +154,7 @@ function Detail({ id, onClose }: { id: number; onClose: () => void }) {
useEffect(() => {
if (!running) return;
let alive = true;
const un = listen<CoreEvent>("core-event", (e) => {
const un = subscribe<CoreEvent>("core-event", (e) => {
const ev = e.payload;
const mine =
(ev.kind === "request_headers" ||
Expand All @@ -167,7 +167,7 @@ function Detail({ id, onClose }: { id: number; onClose: () => void }) {
});
return () => {
alive = false;
void un.then((f) => f());
un();
};
}, [running, id, load]);

Expand Down
14 changes: 7 additions & 7 deletions src/UpdateWindow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useRef, useState, type ReactNode } from "react";
import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import { subscribe } from "@/lib/tauriEvent";
import { getCurrentWindow } from "@tauri-apps/api/window";
import appIcon from "../src-tauri/icons/128x128.png";
import { Banner } from "@/ui/banner";
Expand Down Expand Up @@ -59,22 +59,22 @@ export default function UpdateWindow() {

// 窗口开着的时候又查到了更新的一版 —— 换成新的那一版
useEffect(() => {
const un = listen("update-found", load);
const un = subscribe("update-found", load);
return () => {
void un.then((f) => f());
un();
};
}, [load]);

useEffect(() => {
const a = listen<Step>("update-step", (e) => setStep(e.payload));
const a = subscribe<Step>("update-step", (e) => setStep(e.payload));
// 事件报的是**这一块多大**,不是已下载总量,要自己累加
const b = listen<[number, number | null]>("update-progress", (e) => {
const b = subscribe<[number, number | null]>("update-progress", (e) => {
const [chunk, total] = e.payload;
setProgress(([done, t]) => [done + chunk, total ?? t]);
});
return () => {
void a.then((f) => f());
void b.then((f) => f());
a();
b();
};
}, []);

Expand Down
8 changes: 4 additions & 4 deletions src/connection/useConnection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import { listen } from "@tauri-apps/api/event";
import { subscribe } from "@/lib/tauriEvent";
import { connApi, type ConnView } from "./api";

/**
Expand All @@ -11,10 +11,10 @@ export function useConnection(): ConnView | null {
const [view, setView] = useState<ConnView | null>(null);
useEffect(() => {
let alive = true;
const un = listen<ConnView>("connection", (e) => {
const un = subscribe<ConnView>("connection", (e) => {
if (alive) setView(e.payload);
});
void un
void un.ready
.then(() => connApi.view())
.then((v) => {
if (alive) setView(v);
Expand All @@ -24,7 +24,7 @@ export function useConnection(): ConnView | null {
});
return () => {
alive = false;
void un.then((f) => f());
un();
};
}, []);
return view;
Expand Down
Loading
Loading