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 d90fb6fc9b
commit 5f044e1aed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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")]
pub option: Option<PrfOption>,
/// profile web page url
#[serde(skip_serializing_if = "Option::is_none")]
pub home: Option<String>,
/// the file data
#[serde(skip)]
pub file_data: Option<String>,
@ -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,

View File

@ -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 },

View File

@ -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",

View File

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

View File

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

View File

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