mirror of
https://github.com/vrc-get/vrc-get.git
synced 2026-06-21 09:58:08 +00:00
chore: better url handling
This commit is contained in:
parent
aa14673468
commit
a77ab4a0a3
4 changed files with 27 additions and 3 deletions
|
|
@ -93,6 +93,7 @@ export const commands = {
|
|||
projectSetUnityPath: (projectPath: string, unityPath: string | null) => __TAURI_INVOKE<boolean>("project_set_unity_path", { projectPath, unityPath }),
|
||||
utilOpen: (path: string, ifNotExists: OpenOptions) => __TAURI_INVOKE<null>("util_open", { path, ifNotExists }),
|
||||
utilOpenUrl: (url: string) => __TAURI_INVOKE<null>("util_open_url", { url }),
|
||||
utilOpenUrlNocheck: (url: string) => __TAURI_INVOKE<null>("util_open_url_nocheck", { url }),
|
||||
utilGetLogEntries: () => __TAURI_INVOKE<LogEntry_Serialize[]>("util_get_log_entries"),
|
||||
utilGetVersion: () => __TAURI_INVOKE<string>("util_get_version"),
|
||||
utilCheckForUpdate: () => __TAURI_INVOKE<{
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ function UnityInstallWindow({
|
|||
dialog: DialogContext<void>;
|
||||
}) {
|
||||
const openUnityHub = async () => {
|
||||
await commands.utilOpenUrl(installWithUnityHubLink);
|
||||
await commands.utilOpenUrlNocheck(installWithUnityHubLink);
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -148,6 +148,7 @@ pub(crate) fn handlers() -> impl Fn(Invoke) -> bool + Send + Sync + 'static {
|
|||
project::project_set_unity_path,
|
||||
util::util_open,
|
||||
util::util_open_url,
|
||||
util::util_open_url_nocheck,
|
||||
util::util_get_log_entries,
|
||||
util::util_get_version,
|
||||
util::util_check_for_update,
|
||||
|
|
@ -257,6 +258,7 @@ pub(crate) fn export_ts() {
|
|||
project::project_set_unity_path,
|
||||
util::util_open,
|
||||
util::util_open_url,
|
||||
util::util_open_url_nocheck,
|
||||
util::util_get_log_entries,
|
||||
util::util_get_version,
|
||||
util::util_check_for_update,
|
||||
|
|
@ -506,6 +508,10 @@ struct TauriBasePackageInfo {
|
|||
is_yanked: bool,
|
||||
}
|
||||
|
||||
fn safe_url(url: &url::Url) -> bool {
|
||||
matches!(url.scheme(), "http" | "https")
|
||||
}
|
||||
|
||||
impl TauriBasePackageInfo {
|
||||
fn new(package: &PackageManifest) -> Self {
|
||||
Self {
|
||||
|
|
@ -517,8 +523,14 @@ impl TauriBasePackageInfo {
|
|||
.collect(),
|
||||
version: package.version().into(),
|
||||
unity: package.unity().map(|v| (v.major(), v.minor())),
|
||||
changelog_url: package.changelog_url().map(|v| v.to_string()),
|
||||
documentation_url: package.documentation_url().map(|v| v.to_string()),
|
||||
changelog_url: package
|
||||
.changelog_url()
|
||||
.take_if(|x| safe_url(x))
|
||||
.map(|v| v.to_string()),
|
||||
documentation_url: package
|
||||
.documentation_url()
|
||||
.take_if(|x| safe_url(x))
|
||||
.map(|v| v.to_string()),
|
||||
vpm_dependencies: package
|
||||
.vpm_dependencies()
|
||||
.keys()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use std::path::Path;
|
|||
use crate::commands::async_command::{AsyncCallResult, With, async_command};
|
||||
use crate::commands::environment::settings::TauriPickProjectDefaultPathResult;
|
||||
use crate::commands::prelude::*;
|
||||
use crate::commands::safe_url;
|
||||
use crate::logging::LogEntry;
|
||||
use crate::os::open_that;
|
||||
use crate::updater::{self, Update};
|
||||
|
|
@ -42,9 +43,19 @@ pub async fn util_open(path: String, if_not_exists: OpenOptions) -> Result<(), R
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn util_open_url_nocheck(url: String) -> Result<(), RustError> {
|
||||
open_that(url)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
pub async fn util_open_url(url: String) -> Result<(), RustError> {
|
||||
if !Url::parse(&url).is_ok_and(|x| safe_url(&x)) {
|
||||
return Err(RustError::unrecoverable_str("Bad URL or bad scheme"));
|
||||
}
|
||||
open_that(url)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue