8000 feat: everything needed for quicklink on rust side by SteveLauC · Pull Request #760 · infinilabs/coco-app · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: everything needed for quicklink on rust side #760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions src-tauri/src/common/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ pub(crate) enum OnOpened {
Command {
action: crate::extension::CommandAction,
},
// NOTE that this variant has the same definition as `struct Quicklink`, but we
// cannot use it directly, its `link` field should be deserialized from a string,
// we need a JSON object here.
//
// See also the comments in `struct Quicklink`.
Quicklink {
link: crate::extension::QuicklinkLink,
open_with: String,
},
}

impl OnOpened {
Expand All @@ -57,13 +66,17 @@ impl OnOpened {

ret
}
Self::Quicklink { .. } => String::from("todo"),
}
}
}

#[tauri::command]
pub(crate) async fn open(on_opened: OnOpened) -> Result<(), String> {
log::debug!("open({})", on_opened.url());
pub(crate) async fn open(
on_opened: OnOpened,
extra_args: Option<HashMap<String, String>>,
) -> Result<(), String> {
log::debug!("open({}, {:?})", on_opened.url(), extra_args);

use crate::util::open as homemade_tauri_shell_open;
use crate::GLOBAL_TAURI_APP_HANDLE;
Expand Down Expand Up @@ -107,6 +120,28 @@ pub(crate) async fn open(on_opened: OnOpened) -> Result<(), String> {
));
}
}
OnOpened::Quicklink { link, open_with } => {
let url = link.concatenate_url(&extra_args);

cfg_if::cfg_if! {
if #[cfg(target_os = "macos")] {
let open_with 755B = open_with.as_str();
let mut cmd = Command::new("open");
cmd.arg("-a").arg(open_with).arg(&url);
let output = cmd.output().map_err(|e| format!("failed to spawn open due to error [{}]", e))?;

if !output.status.success() {
return Err(format!(
"failed to open with app {}: {}",
open_with,
String::from_utf8_lossy(&output.stderr)
));
}
} else {
homemade_tauri_shell_open(global_tauri_app_handle.clone(), url).await?
}
}
}
}

Ok(())
Expand Down
Loading
0