feat: support URL Schema 'profile-web-page-url' (#816)

This commit is contained in:
dongchengjie 2024-04-01 19:28:28 +08:00 committed by GitHub
parent 98536250bd
commit 3ee3e7c17b
6 changed files with 30 additions and 2 deletions

View File

@ -46,6 +46,10 @@ pub struct PrfItem {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub option: Option<PrfOption>, pub option: Option<PrfOption>,
/// profile web page url
#[serde(skip_serializing_if = "Option::is_none")]
pub home: Option<String>,
/// the file data /// the file data
#[serde(skip)] #[serde(skip)]
pub file_data: Option<String>, pub file_data: Option<String>,
@ -161,6 +165,7 @@ impl PrfItem {
selected: None, selected: None,
extra: None, extra: None,
option: None, option: None,
home: None,
updated: Some(chrono::Local::now().timestamp() as usize), updated: Some(chrono::Local::now().timestamp() as usize),
file_data: Some(file_data.unwrap_or(tmpl::ITEM_LOCAL.into())), 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 uid = help::get_uid("r");
let file = format!("{uid}.yaml"); let file = format!("{uid}.yaml");
let name = name.unwrap_or(filename.unwrap_or("Remote File".into())); let name = name.unwrap_or(filename.unwrap_or("Remote File".into()));
@ -317,6 +330,7 @@ impl PrfItem {
selected: None, selected: None,
extra, extra,
option, option,
home,
updated: Some(chrono::Local::now().timestamp() as usize), updated: Some(chrono::Local::now().timestamp() as usize),
file_data: Some(data.into()), file_data: Some(data.into()),
}) })
@ -338,6 +352,7 @@ impl PrfItem {
selected: None, selected: None,
extra: None, extra: None,
option: None, option: None,
home: None,
updated: Some(chrono::Local::now().timestamp() as usize), updated: Some(chrono::Local::now().timestamp() as usize),
file_data: Some(tmpl::ITEM_MERGE.into()), file_data: Some(tmpl::ITEM_MERGE.into()),
}) })
@ -356,6 +371,7 @@ impl PrfItem {
desc: Some(desc), desc: Some(desc),
file: Some(file), file: Some(file),
url: None, url: None,
home: None,
selected: None, selected: None,
extra: None, extra: None,
option: None, option: None,

View File

@ -55,6 +55,7 @@ export const ProfileItem = (props: Props) => {
// remote file mode // remote file mode
const hasUrl = !!itemData.url; const hasUrl = !!itemData.url;
const hasExtra = !!extra; // only subscription url has extra info 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 { upload = 0, download = 0, total = 0 } = extra ?? {};
const from = parseUrl(itemData.url); const from = parseUrl(itemData.url);
@ -95,6 +96,11 @@ export const ProfileItem = (props: Props) => {
const [fileOpen, setFileOpen] = useState(false); const [fileOpen, setFileOpen] = useState(false);
const [confirmOpen, setConfirmOpen] = useState(false); const [confirmOpen, setConfirmOpen] = useState(false);
const onOpenHome = () => {
setAnchorEl(null);
window.open(itemData.home); // use built-in browser
};
const onEditInfo = () => { const onEditInfo = () => {
setAnchorEl(null); setAnchorEl(null);
onEdit(); 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: "Select", handler: onForceSelect },
{ label: "Edit Info", handler: onEditInfo }, { label: "Edit Info", handler: onEditInfo },
{ label: "Edit File", handler: onEditFile }, { label: "Edit File", handler: onEditFile },
@ -180,7 +188,7 @@ export const ProfileItem = (props: Props) => {
setConfirmOpen(true); setConfirmOpen(true);
}, },
}, },
]; ]);
const fileModeMenu = [ const fileModeMenu = [
{ label: "Select", handler: onForceSelect }, { label: "Select", handler: onForceSelect },
{ label: "Edit Info", handler: onEditInfo }, { label: "Edit Info", handler: onEditInfo },

View File

@ -30,6 +30,7 @@
"Create Profile": "Create Profile", "Create Profile": "Create Profile",
"Choose File": "Choose File", "Choose File": "Choose File",
"Close All": "Close All", "Close All": "Close All",
"Home": "Home",
"Select": "Select", "Select": "Select",
"Edit Info": "Edit Info", "Edit Info": "Edit Info",
"Edit File": "Edit File", "Edit File": "Edit File",

View File

@ -30,6 +30,7 @@
"Create Profile": "Создать профиль", "Create Profile": "Создать профиль",
"Choose File": "Выбрать файл", "Choose File": "Выбрать файл",
"Close All": "Закрыть всё", "Close All": "Закрыть всё",
"Home": "Главная",
"Select": "Выбрать", "Select": "Выбрать",
"Edit Info": "Изменить информацию", "Edit Info": "Изменить информацию",
"Edit File": "Изменить файл", "Edit File": "Изменить файл",

View File

@ -30,6 +30,7 @@
"Create Profile": "新建订阅", "Create Profile": "新建订阅",
"Choose File": "选择文件", "Choose File": "选择文件",
"Close All": "关闭全部", "Close All": "关闭全部",
"Home": "首页",
"Select": "使用", "Select": "使用",
"Edit Info": "编辑信息", "Edit Info": "编辑信息",
"Edit File": "编辑文件", "Edit File": "编辑文件",

View File

@ -168,6 +168,7 @@ interface IProfileItem {
expire: number; expire: number;
}; };
option?: IProfileOption; option?: IProfileOption;
home?: string;
} }
interface IProfileOption { interface IProfileOption {