diff --git a/src-tauri/src/config/prfitem.rs b/src-tauri/src/config/prfitem.rs index f62e053f..f06fe4db 100644 --- a/src-tauri/src/config/prfitem.rs +++ b/src-tauri/src/config/prfitem.rs @@ -46,6 +46,10 @@ pub struct PrfItem { #[serde(skip_serializing_if = "Option::is_none")] pub option: Option, + /// profile web page url + #[serde(skip_serializing_if = "Option::is_none")] + pub home: Option, + /// the file data #[serde(skip)] pub file_data: Option, @@ -161,6 +165,7 @@ impl PrfItem { selected: None, extra: None, option: None, + home: None, updated: Some(chrono::Local::now().timestamp() as usize), file_data: Some(file_data.unwrap_or(tmpl::ITEM_LOCAL.into())), }) @@ -291,6 +296,14 @@ impl PrfItem { }, }; + let home = match header.get("profile-web-page-url") { + Some(value) => { + let str_value = value.to_str().unwrap_or(""); + Some(str_value.to_string()) + }, + None => None, + }; + let uid = help::get_uid("r"); let file = format!("{uid}.yaml"); let name = name.unwrap_or(filename.unwrap_or("Remote File".into())); @@ -317,6 +330,7 @@ impl PrfItem { selected: None, extra, option, + home, updated: Some(chrono::Local::now().timestamp() as usize), file_data: Some(data.into()), }) @@ -338,6 +352,7 @@ impl PrfItem { selected: None, extra: None, option: None, + home: None, updated: Some(chrono::Local::now().timestamp() as usize), file_data: Some(tmpl::ITEM_MERGE.into()), }) @@ -356,6 +371,7 @@ impl PrfItem { desc: Some(desc), file: Some(file), url: None, + home: None, selected: None, extra: None, option: None, diff --git a/src/components/profile/profile-item.tsx b/src/components/profile/profile-item.tsx index 25601c94..58ab6acf 100644 --- a/src/components/profile/profile-item.tsx +++ b/src/components/profile/profile-item.tsx @@ -55,6 +55,7 @@ export const ProfileItem = (props: Props) => { // remote file mode const hasUrl = !!itemData.url; const hasExtra = !!extra; // only subscription url has extra info + const hasHome = !!itemData.home; // only subscription url has home page const { upload = 0, download = 0, total = 0 } = extra ?? {}; const from = parseUrl(itemData.url); @@ -95,6 +96,11 @@ export const ProfileItem = (props: Props) => { const [fileOpen, setFileOpen] = useState(false); const [confirmOpen, setConfirmOpen] = useState(false); + const onOpenHome = () => { + setAnchorEl(null); + window.open(itemData.home); // use built-in browser + }; + const onEditInfo = () => { setAnchorEl(null); onEdit(); @@ -166,7 +172,9 @@ export const ProfileItem = (props: Props) => { } }); - const urlModeMenu = [ + const urlModeMenu = ( + hasHome ? [{ label: "Home", handler: onOpenHome }] : [] + ).concat([ { label: "Select", handler: onForceSelect }, { label: "Edit Info", handler: onEditInfo }, { label: "Edit File", handler: onEditFile }, @@ -180,7 +188,7 @@ export const ProfileItem = (props: Props) => { setConfirmOpen(true); }, }, - ]; + ]); const fileModeMenu = [ { label: "Select", handler: onForceSelect }, { label: "Edit Info", handler: onEditInfo }, diff --git a/src/locales/en.json b/src/locales/en.json index 7da9f7d8..c513df9c 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -30,6 +30,7 @@ "Create Profile": "Create Profile", "Choose File": "Choose File", "Close All": "Close All", + "Home": "Home", "Select": "Select", "Edit Info": "Edit Info", "Edit File": "Edit File", diff --git a/src/locales/ru.json b/src/locales/ru.json index 1d7f4fdb..b7b5005b 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -30,6 +30,7 @@ "Create Profile": "Создать профиль", "Choose File": "Выбрать файл", "Close All": "Закрыть всё", + "Home": "Главная", "Select": "Выбрать", "Edit Info": "Изменить информацию", "Edit File": "Изменить файл", diff --git a/src/locales/zh.json b/src/locales/zh.json index 06aeed93..76fc2b45 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -30,6 +30,7 @@ "Create Profile": "新建订阅", "Choose File": "选择文件", "Close All": "关闭全部", + "Home": "首页", "Select": "使用", "Edit Info": "编辑信息", "Edit File": "编辑文件", diff --git a/src/services/types.d.ts b/src/services/types.d.ts index 31462643..3de493f1 100644 --- a/src/services/types.d.ts +++ b/src/services/types.d.ts @@ -168,6 +168,7 @@ interface IProfileItem { expire: number; }; option?: IProfileOption; + home?: string; } interface IProfileOption {