mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-23 14:59:24 +01:00
Compare commits
1 Commits
main
...
steve/fix/
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1759e0e56e |
@@ -17,6 +17,8 @@ Information about release notes of Coco App is provided here.
|
||||
|
||||
### ✈️ Improvements
|
||||
|
||||
- refactor: add a timeout to open() #1025
|
||||
|
||||
## 0.10.0 (2025-12-19)
|
||||
|
||||
### ❌ Breaking changes
|
||||
|
||||
@@ -148,9 +148,15 @@ pub(crate) async fn open(
|
||||
extra_args: Option<HashMap<String, Json>>,
|
||||
) -> Result<(), String> {
|
||||
use crate::util::open as homemade_tauri_shell_open;
|
||||
use std::process::Command;
|
||||
use tokio::process::Command;
|
||||
use tokio::time::Duration;
|
||||
use tokio::time::timeout;
|
||||
|
||||
match on_opened {
|
||||
let on_opened_clone = on_opened.clone();
|
||||
// Put the main logic in an async closure so that we can `time::timeout()`
|
||||
// it
|
||||
let async_closure = async move {
|
||||
match on_opened_clone {
|
||||
OnOpened::Application { app_path } => {
|
||||
log::debug!("open application [{}]", app_path);
|
||||
|
||||
@@ -189,7 +195,7 @@ pub(crate) async fn open(
|
||||
if let Some(args) = action.args {
|
||||
cmd.args(args);
|
||||
}
|
||||
let output = cmd.output().map_err(|e| e.to_string())?;
|
||||
let output = cmd.output().await.map_err(|e| e.to_string())?;
|
||||
// Sometimes, we wanna see the result in logs even though it doesn't fail.
|
||||
log::debug!(
|
||||
"executing open(Command) result, exit code: [{}], stdout: [{}], stderr: [{}]",
|
||||
@@ -230,7 +236,7 @@ pub(crate) async fn open(
|
||||
}
|
||||
cmd.arg(&url);
|
||||
|
||||
let output = cmd.output().map_err(|e| format!("failed to spawn [open] due to error [{}]", e))?;
|
||||
let output = cmd.output().await.map_err(|e| format!("failed to spawn [open] due to error [{}]", e))?;
|
||||
|
||||
if !output.status.success() {
|
||||
return Err(format!(
|
||||
@@ -294,6 +300,19 @@ pub(crate) async fn open(
|
||||
}
|
||||
|
||||
Ok(())
|
||||
};
|
||||
|
||||
match timeout(Duration::from_millis(500), async_closure).await {
|
||||
Ok(res) => res,
|
||||
Err(_timed_out) => {
|
||||
log::warn!("executing open(on_opened: [{:?}]) timed out", on_opened);
|
||||
|
||||
Err(format!(
|
||||
"executing open(on_opened: {:?}) timed out",
|
||||
on_opened
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
|
||||
Reference in New Issue
Block a user