Skip to content

Commit d97ab39

Browse files
author
梶塚太智
committed
use crate opener multi-platform complitible
1 parent 7d314fc commit d97ab39

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9+
opener = "0.6.1"
910
powershell_script = "1.1.0"
1011
rand = "0.8"
1112
reqwest = { version = "0.11.0", features = ["blocking"] }

src/main.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use powershell_script::PsScriptBuilder;
22
use rand::seq::SliceRandom;
33
use std::collections::HashMap;
44
use std::env;
5+
use opener;
56
use std::fs::File;
67
use std::io::{self, Error, Read, Write};
78
use std::thread;
@@ -866,20 +867,7 @@ impl Executor {
866867

867868
// ファイルを開く
868869
"open" => {
869-
if cfg!(target_os = "windows") {
870-
let _result = std::process::Command::new("cmd")
871-
.args(&["/C", "start", "", self.pop_stack().get_string().as_str()])
872-
.spawn();
873-
} else if cfg!(target_os = "linux") {
874-
let _result =
875-
std::process::Command::new("xdg-open") // Linuxの場合
876-
.arg(self.pop_stack().get_string().as_str())
877-
.spawn();
878-
} else if cfg!(target_os = "macos") {
879-
let _result = std::process::Command::new("open")
880-
.arg(self.pop_stack().get_string().as_str())
881-
.spawn();
882-
}
870+
let _result = opener::open(self.pop_stack().get_string());
883871
}
884872

885873
// シェルコマンドを実行

0 commit comments

Comments
 (0)