Compare commits
9 Commits
feat-@mona
...
v0.0.4
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,5 +3,3 @@ node_modules
|
|||||||
dist
|
dist
|
||||||
dist-ssr
|
dist-ssr
|
||||||
*.local
|
*.local
|
||||||
package-lock.json
|
|
||||||
yarn.lock
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "clash-verge",
|
"name": "clash-verge",
|
||||||
"version": "0.0.1",
|
"version": "0.0.4",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "cargo tauri dev",
|
"dev": "cargo tauri dev",
|
||||||
@@ -8,8 +8,9 @@
|
|||||||
"web:dev": "vite",
|
"web:dev": "vite",
|
||||||
"web:build": "tsc && vite build",
|
"web:build": "tsc && vite build",
|
||||||
"web:serve": "vite preview",
|
"web:serve": "vite preview",
|
||||||
|
"prepare": "husky install",
|
||||||
"predev": "node scripts/pre-dev.mjs",
|
"predev": "node scripts/pre-dev.mjs",
|
||||||
"prepare": "husky install"
|
"postversion": "node scripts/post-version.mjs"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.7.0",
|
"@emotion/react": "^11.7.0",
|
||||||
|
|||||||
24
scripts/post-version.mjs
Normal file
24
scripts/post-version.mjs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import fs from "fs-extra";
|
||||||
|
import { createRequire } from "module";
|
||||||
|
import { execSync } from "child_process";
|
||||||
|
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
|
// update the tauri conf version
|
||||||
|
async function resolveVersion() {
|
||||||
|
const { version } = require("../package.json");
|
||||||
|
const tauri = require("../src-tauri/tauri.conf.json");
|
||||||
|
|
||||||
|
tauri.package.version = version;
|
||||||
|
|
||||||
|
await fs.writeFile(
|
||||||
|
"./src-tauri/tauri.conf.json",
|
||||||
|
JSON.stringify(tauri, undefined, 2)
|
||||||
|
);
|
||||||
|
execSync("git add ./src-tauri/tauri.conf.json");
|
||||||
|
execSync(`git commit -m v${version} --no-verify`);
|
||||||
|
execSync(`git push`);
|
||||||
|
execSync(`git push origin v${version}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
resolveVersion();
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "clash-verge",
|
"productName": "clash-verge",
|
||||||
"version": "0.0.1"
|
"version": "0.0.4"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
"distDir": "../dist",
|
"distDir": "../dist",
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import {
|
|||||||
} from "@mui/icons-material";
|
} from "@mui/icons-material";
|
||||||
import { updateProxy } from "../services/api";
|
import { updateProxy } from "../services/api";
|
||||||
import { ApiType } from "../services/types";
|
import { ApiType } from "../services/types";
|
||||||
|
import { getProfiles, setProfiles } from "../services/cmds";
|
||||||
|
import noop from "../utils/noop";
|
||||||
|
|
||||||
interface ItemProps {
|
interface ItemProps {
|
||||||
proxy: ApiType.ProxyItem;
|
proxy: ApiType.ProxyItem;
|
||||||
@@ -86,6 +88,24 @@ const ProxyGroup = ({ group }: Props) => {
|
|||||||
try {
|
try {
|
||||||
setNow(name);
|
setNow(name);
|
||||||
await updateProxy(group.name, name);
|
await updateProxy(group.name, name);
|
||||||
|
|
||||||
|
const profiles = await getProfiles().catch(console.error);
|
||||||
|
if (!profiles) return;
|
||||||
|
const profile = profiles.items![profiles.current!]!;
|
||||||
|
if (!profile) return;
|
||||||
|
if (!profile.selected) profile.selected = [];
|
||||||
|
|
||||||
|
const index = profile.selected.findIndex(
|
||||||
|
(item) => item.name === group.name
|
||||||
|
);
|
||||||
|
|
||||||
|
if (index < 0) {
|
||||||
|
profile.selected.push({ name: group.name, now: name });
|
||||||
|
} else {
|
||||||
|
profile.selected[index] = { name: group.name, now: name };
|
||||||
|
}
|
||||||
|
|
||||||
|
setProfiles(profiles.current!, profile).catch(console.error);
|
||||||
} catch {
|
} catch {
|
||||||
setNow(oldValue);
|
setNow(oldValue);
|
||||||
// Todo
|
// Todo
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import useSWR, { useSWRConfig } from "swr";
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
import { List, ListItemText, ListSubheader, Switch } from "@mui/material";
|
import {
|
||||||
|
List,
|
||||||
|
ListItemText,
|
||||||
|
ListSubheader,
|
||||||
|
Switch,
|
||||||
|
Typography,
|
||||||
|
} from "@mui/material";
|
||||||
import {
|
import {
|
||||||
getVergeConfig,
|
getVergeConfig,
|
||||||
patchVergeConfig,
|
patchVergeConfig,
|
||||||
@@ -9,6 +15,7 @@ import { CmdType } from "../services/types";
|
|||||||
import GuardState from "./guard-state";
|
import GuardState from "./guard-state";
|
||||||
import SettingItem from "./setting-item";
|
import SettingItem from "./setting-item";
|
||||||
import PaletteSwitch from "./palette-switch";
|
import PaletteSwitch from "./palette-switch";
|
||||||
|
import { version } from "../../package.json";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onError?: (err: Error) => void;
|
onError?: (err: Error) => void;
|
||||||
@@ -82,6 +89,11 @@ const SettingVerge = ({ onError }: Props) => {
|
|||||||
<Switch edge="end" />
|
<Switch edge="end" />
|
||||||
</GuardState>
|
</GuardState>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
|
||||||
|
<SettingItem>
|
||||||
|
<ListItemText primary="Version" />
|
||||||
|
<Typography sx={{ py: "6px" }}>v{version}</Typography>
|
||||||
|
</SettingItem>
|
||||||
</List>
|
</List>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import { useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import useSWR, { useSWRConfig } from "swr";
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
import { Box, Button, Grid, TextField, Typography } from "@mui/material";
|
import { Box, Button, Grid, TextField, Typography } from "@mui/material";
|
||||||
import { getProfiles, importProfile, putProfiles } from "../services/cmds";
|
import {
|
||||||
import { getProxies } from "../services/api";
|
getProfiles,
|
||||||
|
putProfiles,
|
||||||
|
setProfiles,
|
||||||
|
importProfile,
|
||||||
|
} from "../services/cmds";
|
||||||
|
import { getProxies, updateProxy } from "../services/api";
|
||||||
import ProfileItemComp from "../components/profile-item";
|
import ProfileItemComp from "../components/profile-item";
|
||||||
import useNotice from "../utils/use-notice";
|
import useNotice from "../utils/use-notice";
|
||||||
import noop from "../utils/noop";
|
import noop from "../utils/noop";
|
||||||
@@ -15,6 +20,43 @@ const ProfilePage = () => {
|
|||||||
const { mutate } = useSWRConfig();
|
const { mutate } = useSWRConfig();
|
||||||
const { data: profiles = {} } = useSWR("getProfiles", getProfiles);
|
const { data: profiles = {} } = useSWR("getProfiles", getProfiles);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (profiles.current == null) return;
|
||||||
|
|
||||||
|
const profile = profiles.items![profiles.current];
|
||||||
|
if (!profile) return;
|
||||||
|
|
||||||
|
getProxies().then((proxiesData) => {
|
||||||
|
mutate("getProxies", proxiesData);
|
||||||
|
// init selected array
|
||||||
|
const { selected = [] } = profile;
|
||||||
|
const selectedMap = Object.fromEntries(
|
||||||
|
selected.map((each) => [each.name!, each.now!])
|
||||||
|
);
|
||||||
|
// todo: enhance error handle
|
||||||
|
let hasChange = false;
|
||||||
|
proxiesData.groups.forEach((group) => {
|
||||||
|
const { name, now } = group;
|
||||||
|
|
||||||
|
if (!now || selectedMap[name] === now) return;
|
||||||
|
if (selectedMap[name] == null) {
|
||||||
|
selectedMap[name] = now!;
|
||||||
|
} else {
|
||||||
|
hasChange = true;
|
||||||
|
updateProxy(name, selectedMap[name]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// update profile selected list
|
||||||
|
profile.selected = Object.entries(selectedMap).map(([name, now]) => ({
|
||||||
|
name,
|
||||||
|
now,
|
||||||
|
}));
|
||||||
|
setProfiles(profiles.current!, profile).catch(console.error);
|
||||||
|
// update proxies cache
|
||||||
|
if (hasChange) mutate("getProxies", getProxies());
|
||||||
|
});
|
||||||
|
}, [profiles]);
|
||||||
|
|
||||||
const onImport = async () => {
|
const onImport = async () => {
|
||||||
if (!url) return;
|
if (!url) return;
|
||||||
setUrl("");
|
setUrl("");
|
||||||
@@ -39,7 +81,6 @@ const ProfilePage = () => {
|
|||||||
putProfiles(index)
|
putProfiles(index)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate("getProfiles", { ...profiles, current: index }, true);
|
mutate("getProfiles", { ...profiles, current: index }, true);
|
||||||
mutate("getProxies", getProxies());
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { getProxies } from "../services/api";
|
|||||||
import ProxyGroup from "../components/proxy-group";
|
import ProxyGroup from "../components/proxy-group";
|
||||||
|
|
||||||
const ProxyPage = () => {
|
const ProxyPage = () => {
|
||||||
const { data } = useSWR("getProxies", getProxies);
|
const { data: proxiesData } = useSWR("getProxies", getProxies);
|
||||||
const { groups = [] } = data ?? {};
|
const { groups = [] } = proxiesData ?? {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ width: 0.9, maxWidth: "850px", mx: "auto", mb: 2 }}>
|
<Box sx={{ width: 0.9, maxWidth: "850px", mx: "auto", mb: 2 }}>
|
||||||
|
|||||||
@@ -25,11 +25,8 @@ export async function getProfiles() {
|
|||||||
return (await invoke<CmdType.ProfilesConfig>("get_profiles")) ?? {};
|
return (await invoke<CmdType.ProfilesConfig>("get_profiles")) ?? {};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setProfiles(
|
export async function setProfiles(index: number, profile: CmdType.ProfileItem) {
|
||||||
current: number,
|
return invoke<void>("set_profiles", { index, profile });
|
||||||
profile: CmdType.ProfileItem
|
|
||||||
) {
|
|
||||||
return invoke<void>("set_profiles", { current, profile });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function putProfiles(current: number) {
|
export async function putProfiles(current: number) {
|
||||||
|
|||||||
Reference in New Issue
Block a user