notification of exceeding the number of devices in the subscription, support for vless:// links with templates by @legiz-ru
This commit is contained in:
53
src/components/profile/hwid-error-dialog.tsx
Normal file
53
src/components/profile/hwid-error-dialog.tsx
Normal file
@@ -0,0 +1,53 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogDescription,
|
||||
DialogFooter
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { AlertTriangle } from "lucide-react";
|
||||
|
||||
export const HwidErrorDialog = () => {
|
||||
const { t } = useTranslation();
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const handleShowHwidError = (event: Event) => {
|
||||
const customEvent = event as CustomEvent<string>;
|
||||
setErrorMessage(customEvent.detail);
|
||||
};
|
||||
|
||||
window.addEventListener('show-hwid-error', handleShowHwidError);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('show-hwid-error', handleShowHwidError);
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (!errorMessage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={!!errorMessage} onOpenChange={() => setErrorMessage(null)}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<AlertTriangle className="h-5 w-5 text-destructive" />
|
||||
{t("Device Limit Reached")}
|
||||
</DialogTitle>
|
||||
<DialogDescription className="pt-4 text-left">
|
||||
{errorMessage}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button onClick={() => setErrorMessage(null)}>{t("OK")}</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
@@ -12,13 +12,14 @@ import {
|
||||
createProfile,
|
||||
patchProfile,
|
||||
importProfile,
|
||||
enhanceProfiles,
|
||||
enhanceProfiles, createProfileFromShareLink,
|
||||
} from "@/services/cmds";
|
||||
import { useProfiles } from "@/hooks/use-profiles";
|
||||
import { showNotice } from "@/services/noticeService";
|
||||
import { version } from "@root/package.json";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -72,6 +73,7 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
||||
const [isCheckingUrl, setIsCheckingUrl] = useState(false);
|
||||
const [isImporting, setIsImporting] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [selectedTemplate, setSelectedTemplate] = useState("default");
|
||||
|
||||
const form = useForm<IProfileItem>({
|
||||
defaultValues: {
|
||||
@@ -136,14 +138,9 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
||||
setIsCheckingUrl(true);
|
||||
|
||||
const handler = setTimeout(() => {
|
||||
try {
|
||||
new URL(importUrl);
|
||||
setIsUrlValid(true);
|
||||
} catch (error) {
|
||||
setIsUrlValid(false);
|
||||
} finally {
|
||||
setIsCheckingUrl(false);
|
||||
}
|
||||
const isValid = /^(https?|vmess|vless|ss|socks|trojan):\/\//.test(importUrl);
|
||||
setIsUrlValid(isValid);
|
||||
setIsCheckingUrl(false);
|
||||
}, 500);
|
||||
return () => {
|
||||
clearTimeout(handler);
|
||||
@@ -151,30 +148,40 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
||||
}, [importUrl]);
|
||||
|
||||
const handleImport = useLockFn(async () => {
|
||||
if (!importUrl) return;
|
||||
if (!importUrl || !isUrlValid) return;
|
||||
setIsImporting(true);
|
||||
|
||||
const isShareLink = /^(vmess|vless|ss|socks|trojan):\/\//.test(importUrl);
|
||||
|
||||
try {
|
||||
await importProfile(importUrl);
|
||||
showNotice("success", t("Profile Imported Successfully"));
|
||||
if (isShareLink) {
|
||||
await createProfileFromShareLink(importUrl, selectedTemplate);
|
||||
showNotice("success", t("Profile created from link successfully"));
|
||||
} else {
|
||||
await importProfile(importUrl);
|
||||
showNotice("success", t("Profile Imported Successfully"));
|
||||
}
|
||||
props.onChange();
|
||||
await enhanceProfiles();
|
||||
setOpen(false);
|
||||
} catch (err) {
|
||||
showNotice("info", t("Import failed, retrying with Clash proxy..."));
|
||||
try {
|
||||
await importProfile(importUrl, {
|
||||
with_proxy: false,
|
||||
self_proxy: true,
|
||||
});
|
||||
showNotice("success", t("Profile Imported with Clash proxy"));
|
||||
props.onChange();
|
||||
await enhanceProfiles();
|
||||
setOpen(false);
|
||||
} catch (retryErr: any) {
|
||||
showNotice(
|
||||
"error",
|
||||
`${t("Import failed even with Clash proxy")}: ${retryErr?.message || retryErr.toString()}`,
|
||||
);
|
||||
} catch (err: any) {
|
||||
const errorMessage = typeof err === 'string' ? err : (err.message || String(err));
|
||||
const lowerErrorMessage = errorMessage.toLowerCase();
|
||||
if (lowerErrorMessage.includes('device') || lowerErrorMessage.includes('устройств')) {
|
||||
window.dispatchEvent(new CustomEvent('show-hwid-error', { detail: errorMessage }));
|
||||
} else if (!isShareLink && errorMessage.includes("failed to fetch")) {
|
||||
showNotice("info", t("Import failed, retrying with Clash proxy..."));
|
||||
try {
|
||||
await importProfile(importUrl, { with_proxy: false, self_proxy: true });
|
||||
showNotice("success", t("Profile Imported with Clash proxy"));
|
||||
props.onChange();
|
||||
await enhanceProfiles();
|
||||
setOpen(false);
|
||||
} catch (retryErr: any) {
|
||||
showNotice("error", `${t("Import failed even with Clash proxy")}: ${retryErr?.message || retryErr.toString()}`);
|
||||
}
|
||||
} else {
|
||||
showNotice("error", errorMessage);
|
||||
}
|
||||
} finally {
|
||||
setIsImporting(false);
|
||||
@@ -294,6 +301,21 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/^(vmess|vless|ss|socks|trojan):\/\//.test(importUrl) && (
|
||||
<div className="space-y-2">
|
||||
<Label>{t("Template")}</Label>
|
||||
<Select value={selectedTemplate} onValueChange={setSelectedTemplate}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select a template..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="default">{t("Default Template")}</SelectItem>
|
||||
<SelectItem value="without_ru">{t("Template without RU Rules")}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setShowAdvanced(!showAdvanced)}
|
||||
@@ -440,7 +462,7 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
|
||||
<FormLabel>User Agent</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder={`clash-verge/v${version}`}
|
||||
placeholder={`koala-clash/v${version}`}
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
|
||||
@@ -235,7 +235,7 @@
|
||||
"uninstall": "uninstalled",
|
||||
"active": "active",
|
||||
"unknown": "unknown",
|
||||
"Information: Please make sure that the Clash Verge Service is installed and enabled": "Information: Please make sure that the Clash Verge Service is installed and enabled",
|
||||
"Information: Please make sure that the Clash Verge Service is installed and enabled": "Information: Please make sure that the Koala Clash Service is installed and enabled",
|
||||
"Install": "Install",
|
||||
"Uninstall": "Uninstall",
|
||||
"Disable Service Mode": "Disable Service Mode",
|
||||
@@ -511,7 +511,7 @@
|
||||
"Validate Merge File": "Validate Merge File",
|
||||
"Validation Success": "Validation Success",
|
||||
"Validation Failed": "Validation Failed",
|
||||
"Service Administrator Prompt": "Clash Verge requires administrator privileges to reinstall the system service",
|
||||
"Service Administrator Prompt": "Koala Clash requires administrator privileges to reinstall the system service",
|
||||
"DNS Settings": "DNS Settings",
|
||||
"DNS settings saved": "DNS settings saved",
|
||||
"DNS Overwrite": "DNS Overwrite",
|
||||
@@ -665,5 +665,7 @@
|
||||
"Send HWID": "Send HWID",
|
||||
"New Version is available": "New Version is available",
|
||||
"New Version": "New Version",
|
||||
"New update": "New update"
|
||||
"New update": "New update",
|
||||
"Device Limit Reached": "Device Limit Reached",
|
||||
"Update Profile": "Update Profile"
|
||||
}
|
||||
|
||||
@@ -200,7 +200,7 @@
|
||||
"Settings": "Настройки",
|
||||
"System Setting": "Настройки системы",
|
||||
"Tun Mode": "Режим TUN",
|
||||
"TUN requires Service Mode": "Режим TUN требует установленную службу Clash Verge",
|
||||
"TUN requires Service Mode": "Режим TUN требует установленную службу Koala Clash",
|
||||
"Install Service": "Установить службу",
|
||||
"Reset to Default": "Сбросить настройки",
|
||||
"Tun Mode Info": "Режим Tun: захватывает весь системный трафик, при включении нет необходимости включать системный прокси-сервер.",
|
||||
@@ -208,7 +208,7 @@
|
||||
"System Proxy Disabled": "Системный прокси отключен, большинству пользователей рекомендуется включить эту опцию",
|
||||
"TUN Mode Enabled": "Режим TUN включен, приложения будут получать доступ к сети через виртуальную сетевую карту",
|
||||
"TUN Mode Disabled": "Режим TUN отключен",
|
||||
"TUN Mode Service Required": "Режим TUN требует установленную службу Clash Verge",
|
||||
"TUN Mode Service Required": "Режим TUN требует установленную службу Koala Clash",
|
||||
"TUN Mode Intercept Info": "Режим TUN может перехватить трафик всех приложений, подходит для приложений, которые не работают в режиме системного прокси.",
|
||||
"Rule Mode Description": "Направляет трафик в соответствии с предустановленными правилами",
|
||||
"Global Mode Description": "Направляет весь трафик через прокси-серверы",
|
||||
@@ -229,7 +229,7 @@
|
||||
"uninstall": "Не установленный",
|
||||
"active": "Активированный",
|
||||
"unknown": "неизвестный",
|
||||
"Information: Please make sure that the Clash Verge Service is installed and enabled": "Информация: Пожалуйста, убедитесь, что сервис Clash Verge Service установлен и включен",
|
||||
"Information: Please make sure that the Clash Verge Service is installed and enabled": "Информация: Пожалуйста, убедитесь, что сервис Koala Clash Service установлен и включен",
|
||||
"Install": "Установить",
|
||||
"Uninstall": "Удалить",
|
||||
"Disable Service Mode": "Отключить режим системной службы",
|
||||
@@ -372,7 +372,7 @@
|
||||
"Export Diagnostic Info": "Экспорт диагностической информации",
|
||||
"Export Diagnostic Info For Issue Reporting": "Экспорт диагностической информации для отчета об ошибке",
|
||||
"Exit": "Выход",
|
||||
"Verge Version": "Версия Clash Verge Rev",
|
||||
"Verge Version": "Версия Koala Clash",
|
||||
"ReadOnly": "Только для чтения",
|
||||
"ReadOnlyMessage": "Невозможно редактировать в режиме только для чтения",
|
||||
"Filter": "Фильтр",
|
||||
@@ -489,7 +489,7 @@
|
||||
"Validate Merge File": "Проверить Merge File",
|
||||
"Validation Success": "Файл успешно проверен",
|
||||
"Validation Failed": "Проверка не удалась",
|
||||
"Service Administrator Prompt": "Clash Verge требует прав администратора для переустановки системной службы",
|
||||
"Service Administrator Prompt": "Koala Clash требует прав администратора для переустановки системной службы",
|
||||
"DNS Settings": "Настройки DNS",
|
||||
"DNS Overwrite": "Переопределение настроек DNS",
|
||||
"DNS Settings Warning": "Если вы не знакомы с этими настройками, пожалуйста, не изменяйте и не отключайте их",
|
||||
@@ -617,5 +617,7 @@
|
||||
"Send HWID": "Отправлять HWID",
|
||||
"New Version is available": "Доступна новая версия",
|
||||
"New Version": "Новая версия",
|
||||
"New update": "Доступно обновление"
|
||||
"New update": "Доступно обновление",
|
||||
"Device Limit Reached": "Достигнут лимит устройств",
|
||||
"Update Profile": "Обновить профиль"
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ import { showNotice } from "@/services/noticeService";
|
||||
import { NoticeManager } from "@/components/base/NoticeManager";
|
||||
import { SidebarProvider, useSidebar } from "@/components/ui/sidebar";
|
||||
import { AppSidebar } from "@/components/layout/sidebar";
|
||||
import {useZoomControls} from "@/hooks/useZoomControls";
|
||||
import { useZoomControls } from "@/hooks/useZoomControls";
|
||||
import { HwidErrorDialog } from "@/components/profile/hwid-error-dialog";
|
||||
|
||||
|
||||
const appWindow = getCurrentWebviewWindow();
|
||||
export let portableFlag = false;
|
||||
@@ -50,8 +52,13 @@ const handleNoticeMessage = (
|
||||
sessionStorage.setItem('activateProfile', msg);
|
||||
break;
|
||||
case "import_sub_url::error":
|
||||
showNotice("error", msg);
|
||||
break;
|
||||
console.log(msg);
|
||||
if (msg.toLowerCase().includes('device') || msg.toLowerCase().includes('устройств')) {
|
||||
window.dispatchEvent(new CustomEvent('show-hwid-error', { detail: msg }));
|
||||
} else {
|
||||
showNotice("error", msg);
|
||||
}
|
||||
break;
|
||||
case "set_config::error":
|
||||
showNotice("error", msg);
|
||||
break;
|
||||
@@ -456,6 +463,7 @@ const Layout = () => {
|
||||
{routersEles && React.cloneElement(routersEles, { key: location.pathname })}
|
||||
</div>
|
||||
</main>
|
||||
<HwidErrorDialog />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -400,3 +400,7 @@ export const isAdmin = async () => {
|
||||
export async function getNextUpdateTime(uid: string) {
|
||||
return invoke<number | null>("get_next_update_time", { uid });
|
||||
}
|
||||
|
||||
export async function createProfileFromShareLink(link: string, templateName: string) {
|
||||
return invoke<void>("create_profile_from_share_link", { link, templateName });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user