Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Clash Verge
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Clash Verge
Commits
a12f58c1
There was an error fetching the commit references. Please try again later.
Unverified
Commit
a12f58c1
authored
3 years ago
by
GyDi
Browse files
Options
Downloads
Patches
Plain Diff
feat: use crate open
parent
b5283eaa
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src-tauri/Cargo.lock
+1
-0
1 addition, 0 deletions
src-tauri/Cargo.lock
src-tauri/Cargo.toml
+1
-0
1 addition, 0 deletions
src-tauri/Cargo.toml
src-tauri/src/cmds.rs
+6
-60
6 additions, 60 deletions
src-tauri/src/cmds.rs
with
8 additions
and
60 deletions
src-tauri/Cargo.lock
+
1
−
0
View file @
a12f58c1
...
@@ -441,6 +441,7 @@ dependencies = [
...
@@ -441,6 +441,7 @@ dependencies = [
"log",
"log",
"log4rs",
"log4rs",
"nanoid",
"nanoid",
"open",
"port_scanner",
"port_scanner",
"reqwest",
"reqwest",
"serde",
"serde",
...
...
This diff is collapsed.
Click to expand it.
src-tauri/Cargo.toml
+
1
−
0
View file @
a12f58c1
...
@@ -15,6 +15,7 @@ tauri-build = { version = "1.0.0-rc.4", features = [] }
...
@@ -15,6 +15,7 @@ tauri-build = { version = "1.0.0-rc.4", features = [] }
[dependencies]
[dependencies]
anyhow
=
"1.0"
anyhow
=
"1.0"
dirs
=
"4.0.0"
dirs
=
"4.0.0"
open
=
"2.1.1"
dunce
=
"1.0.2"
dunce
=
"1.0.2"
nanoid
=
"0.4.0"
nanoid
=
"0.4.0"
chrono
=
"0.4.19"
chrono
=
"0.4.19"
...
...
This diff is collapsed.
Click to expand it.
src-tauri/src/cmds.rs
+
6
−
60
View file @
a12f58c1
...
@@ -6,7 +6,7 @@ use crate::{
...
@@ -6,7 +6,7 @@ use crate::{
use
crate
::{
ret_err
,
wrap_err
};
use
crate
::{
ret_err
,
wrap_err
};
use
anyhow
::
Result
;
use
anyhow
::
Result
;
use
serde_yaml
::
Mapping
;
use
serde_yaml
::
Mapping
;
use
std
::
{
path
::
PathBuf
,
process
::
Command
}
;
use
std
::
process
::
Command
;
use
tauri
::{
api
,
Manager
,
State
};
use
tauri
::{
api
,
Manager
,
State
};
/// get all profiles from `profiles.yaml`
/// get all profiles from `profiles.yaml`
...
@@ -195,21 +195,21 @@ pub fn view_profile(index: String, profiles_state: State<'_, ProfilesState>) ->
...
@@ -195,21 +195,21 @@ pub fn view_profile(index: String, profiles_state: State<'_, ProfilesState>) ->
.arg
(
path
)
.arg
(
path
)
.spawn
()
.spawn
()
{
{
log
::
error!
(
"{err}"
);
log
::
error!
(
"
failed to open file by VScode for
{err}"
);
return
Err
(
"failed to open file by VScode"
.into
());
return
Err
(
"failed to open file by VScode"
.into
());
}
}
}
}
#[cfg(not(target_os
=
"windows"
))]
#[cfg(not(target_os
=
"windows"
))]
if
let
Err
(
err
)
=
Command
::
new
(
code
)
.arg
(
path
)
.spawn
()
{
if
let
Err
(
err
)
=
Command
::
new
(
code
)
.arg
(
path
)
.spawn
()
{
log
::
error!
(
"{err}"
);
log
::
error!
(
"
failed to open file by VScode for
{err}"
);
return
Err
(
"failed to open file by VScode"
.into
());
return
Err
(
"failed to open file by VScode"
.into
());
}
}
return
Ok
(());
return
Ok
(());
}
}
open_path_cmd
(
path
,
"failed to open file by `open`"
)
wrap_err!
(
open
::
that
(
path
)
)
}
}
/// restart the sidecar
/// restart the sidecar
...
@@ -323,66 +323,12 @@ pub fn kill_sidecars() {
...
@@ -323,66 +323,12 @@ pub fn kill_sidecars() {
#[tauri::command]
#[tauri::command]
pub
fn
open_app_dir
()
->
Result
<
(),
String
>
{
pub
fn
open_app_dir
()
->
Result
<
(),
String
>
{
let
app_dir
=
dirs
::
app_home_dir
();
let
app_dir
=
dirs
::
app_home_dir
();
open_path_cmd
(
app_dir
,
"failed to open
app
dir
"
)
wrap_err!
(
open
::
that
(
app
_
dir
)
)
}
}
/// open logs dir
/// open logs dir
#[tauri::command]
#[tauri::command]
pub
fn
open_logs_dir
()
->
Result
<
(),
String
>
{
pub
fn
open_logs_dir
()
->
Result
<
(),
String
>
{
let
log_dir
=
dirs
::
app_logs_dir
();
let
log_dir
=
dirs
::
app_logs_dir
();
open_path_cmd
(
log_dir
,
"failed to open logs dir"
)
wrap_err!
(
open
::
that
(
log_dir
))
}
/// use the os default open command to open file or dir
fn
open_path_cmd
(
path
:
PathBuf
,
err_str
:
&
str
)
->
Result
<
(),
String
>
{
let
result
;
#[cfg(target_os
=
"windows"
)]
{
use
std
::
os
::
windows
::
process
::
CommandExt
;
result
=
Command
::
new
(
"explorer"
)
.creation_flags
(
0x08000000
)
.arg
(
&
path
)
.spawn
();
}
#[cfg(target_os
=
"macos"
)]
{
result
=
Command
::
new
(
"open"
)
.arg
(
&
path
)
.spawn
();
}
#[cfg(target_os
=
"linux"
)]
{
result
=
Command
::
new
(
"xdg-open"
)
.arg
(
&
path
)
.spawn
();
}
match
result
{
Ok
(
child
)
=>
match
child
.wait_with_output
()
{
Ok
(
out
)
=>
{
// 退出码不为0 不一定没有调用成功
// 因此仅做warn log且不返回错误
if
let
Some
(
code
)
=
out
.status
.code
()
{
if
code
!=
0
{
log
::
warn!
(
"failed to open {:?} (code {})"
,
&
path
,
code
);
log
::
warn!
(
"open cmd stdout: {}, stderr: {}"
,
String
::
from_utf8_lossy
(
&
out
.stdout
),
String
::
from_utf8_lossy
(
&
out
.stderr
),
);
}
}
}
Err
(
err
)
=>
{
log
::
error!
(
"failed to open {:?} for {err}"
,
&
path
);
return
Err
(
err_str
.into
());
}
},
Err
(
err
)
=>
{
log
::
error!
(
"failed to open {:?} for {err}"
,
&
path
);
return
Err
(
err_str
.into
());
}
}
return
Ok
(());
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment