Merge branch 'fix-migrate-tauri2-errors'

* fix-migrate-tauri2-errors: (288 commits)

# Conflicts:
#	.github/ISSUE_TEMPLATE/bug_report.yml
This commit is contained in:
huzibaca
2024-11-24 00:14:46 +08:00
123 changed files with 8721 additions and 5789 deletions

View File

@@ -47,13 +47,15 @@ import { useProfiles } from "@/hooks/use-profiles";
import { ConfigViewer } from "@/components/setting/mods/config-viewer";
import { throttle } from "lodash-es";
import { BaseStyledTextField } from "@/components/base/base-styled-text-field";
import { listen } from "@tauri-apps/api/event";
import { readTextFile } from "@tauri-apps/plugin-fs";
import { readText } from "@tauri-apps/plugin-clipboard-manager";
import { useLocation } from "react-router-dom";
import { useListen } from "@/hooks/use-listen";
const ProfilePage = () => {
const { t } = useTranslation();
const location = useLocation();
const { addListener } = useListen();
const [url, setUrl] = useState("");
const [disabled, setDisabled] = useState(false);
const [activatings, setActivatings] = useState<string[]>([]);
@@ -62,11 +64,12 @@ const ProfilePage = () => {
useSensor(PointerSensor),
useSensor(KeyboardSensor, {
coordinateGetter: sortableKeyboardCoordinates,
})
}),
);
const { current } = location.state || {};
useEffect(() => {
const unlisten = listen("tauri://file-drop", async (event) => {
const unlisten = addListener("tauri://file-drop", async (event) => {
const fileList = event.payload as string[];
for (let file of fileList) {
if (!file.endsWith(".yaml") && !file.endsWith(".yml")) {
@@ -102,7 +105,7 @@ const ProfilePage = () => {
const { data: chainLogs = {}, mutate: mutateLogs } = useSWR(
"getRuntimeLogs",
getRuntimeLogs
getRuntimeLogs,
);
const viewerRef = useRef<ProfileViewerRef>(null);
@@ -132,23 +135,8 @@ const ProfilePage = () => {
Notice.success(t("Profile Imported Successfully"));
setUrl("");
setLoading(false);
getProfiles().then(async (newProfiles) => {
mutate("getProfiles", newProfiles);
const remoteItem = newProfiles.items?.find((e) => e.type === "remote");
const profilesCount = newProfiles.items?.filter(
(e) => e.type === "remote" || e.type === "local"
).length as number;
if (remoteItem && (profilesCount == 1 || !newProfiles.current)) {
const current = remoteItem.uid;
await patchProfiles({ current });
mutateLogs();
setTimeout(() => activateSelected(), 2000);
}
});
mutateProfiles();
await onEnhance(false);
} catch (err: any) {
Notice.error(err.message || err.toString());
setLoading(false);
@@ -168,33 +156,49 @@ const ProfilePage = () => {
}
};
const onSelect = useLockFn(async (current: string, force: boolean) => {
if (!force && current === profiles.current) return;
const activateProfile = async (profile: string, notifySuccess: boolean) => {
// 避免大多数情况下loading态闪烁
const reset = setTimeout(() => {
setActivatings([...currentActivatings(), current]);
setActivatings((prev) => [...prev, profile]);
}, 100);
try {
await patchProfiles({ current });
await patchProfiles({ current: profile });
await mutateLogs();
closeAllConnections();
activateSelected().then(() => {
await activateSelected();
if (notifySuccess) {
Notice.success(t("Profile Switched"), 1000);
});
}
} catch (err: any) {
Notice.error(err?.message || err.toString(), 4000);
} finally {
clearTimeout(reset);
setActivatings([]);
}
};
const onSelect = useLockFn(async (current: string, force: boolean) => {
if (!force && current === profiles.current) return;
await activateProfile(current, true);
});
const onEnhance = useLockFn(async () => {
useEffect(() => {
(async () => {
if (current) {
mutateProfiles();
await activateProfile(current, false);
}
})();
}, current);
const onEnhance = useLockFn(async (notifySuccess: boolean) => {
setActivatings(currentActivatings());
try {
await enhanceProfiles();
mutateLogs();
Notice.success(t("Profile Reactivated"), 1000);
if (notifySuccess) {
Notice.success(t("Profile Reactivated"), 1000);
}
} catch (err: any) {
Notice.error(err.message || err.toString(), 3000);
} finally {
@@ -209,7 +213,7 @@ const ProfilePage = () => {
await deleteProfile(uid);
mutateProfiles();
mutateLogs();
current && (await onEnhance());
current && (await onEnhance(false));
} catch (err: any) {
Notice.error(err?.message || err.toString());
} finally {
@@ -236,7 +240,7 @@ const ProfilePage = () => {
setLoadingCache((cache) => {
// 获取没有正在更新的订阅
const items = profileItems.filter(
(e) => e.type === "remote" && !cache[e.uid]
(e) => e.type === "remote" && !cache[e.uid],
);
const change = Object.fromEntries(items.map((e) => [e.uid, true]));
@@ -286,7 +290,7 @@ const ProfilePage = () => {
size="small"
color="primary"
title={t("Reactivate Profiles")}
onClick={onEnhance}
onClick={() => onEnhance(true)}
>
<LocalFireDepartmentRounded />
</IconButton>
@@ -385,7 +389,7 @@ const ProfilePage = () => {
onEdit={() => viewerRef.current?.edit(item)}
onSave={async (prev, curr) => {
if (prev !== curr && profiles.current === item.uid) {
await onEnhance();
await onEnhance(false);
}
}}
onDelete={() => onDelete(item.uid)}
@@ -408,7 +412,7 @@ const ProfilePage = () => {
id="Merge"
onSave={async (prev, curr) => {
if (prev !== curr) {
await onEnhance();
await onEnhance(false);
}
}}
/>
@@ -419,7 +423,7 @@ const ProfilePage = () => {
logInfo={chainLogs["Script"]}
onSave={async (prev, curr) => {
if (prev !== curr) {
await onEnhance();
await onEnhance(false);
}
}}
/>
@@ -428,7 +432,13 @@ const ProfilePage = () => {
</Box>
</Box>
<ProfileViewer ref={viewerRef} onChange={() => mutateProfiles()} />
<ProfileViewer
ref={viewerRef}
onChange={async () => {
mutateProfiles();
await onEnhance(false);
}}
/>
<ConfigViewer ref={configRef} />
</BasePage>
);