Skip to content

Commit

Permalink
update logic
Browse files Browse the repository at this point in the history
close #1
  • Loading branch information
Mikachu2333 authored Jun 7, 2024
1 parent 1140f15 commit 9281a49
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sc_starter"
version = "1.1.0"
version = "1.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion res/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Ctrl+Alt=O
#
# ③格式如下:
# 「控制键1」+「控制键2」+「……」=「实际键」
# 【⚠️注意】:为了避免您设定的快捷键与当前系统中其他软件使用的快捷键冲突,请至少选定两个「控制键」,且尽量不要使用「Ctrl」+「Shift」=「X」样式的快捷键。
# 【⚠️注意】:为了避免您设定的快捷键与当前系统中其他软件使用的快捷键冲突,请至少选定两个「控制键」,且尽量不要使用「Ctrl」+「Shift」=「X」样式的快捷键。如快捷键未成功设置,将使用默认快捷键。
#
# 可用的控制键列表如下(大小写均可):
# WIN / WINDOWS / SUPER
Expand Down
65 changes: 35 additions & 30 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ fn unzip_res(paths: &PathInfos, exists: &FileExist) {
println!("Finish release Exe.");
}

fn operate_exe(path: &PathBuf, mode: u8) {
fn operate_exe(path: &PathBuf, mode: usize) {
match mode {
0 => {
exit(0);
Command::new(&path).spawn().unwrap();
}
1 => {
Command::new(&path).spawn().unwrap();
Command::new(&path).arg("--pin:clipboard").spawn().unwrap();
}
2 => {
Command::new(&path).arg("--pin:clipboard").spawn().unwrap();
exit(0);
}
3 => {
Command::new("explorer.exe").arg(&path).spawn().unwrap();
Expand All @@ -131,18 +131,19 @@ fn set_hotkeys(
let res_path = exe_path.clone();
let key_groups = key_groups;
let mut hkm = HotkeyManager::new();

hkm.register(key_groups[0].vkey, &key_groups[0].mod_keys, move || {
operate_exe(&exe_path, 1);
operate_exe(&exe_path, 0);
})
.unwrap();

hkm.register(key_groups[1].vkey, &key_groups[1].mod_keys, move || {
operate_exe(&res_path, 2);
operate_exe(&res_path, 1);
})
.unwrap();

hkm.register(key_groups[2].vkey, &key_groups[2].mod_keys, move || {
operate_exe(&PathBuf::new(), 0);
operate_exe(&PathBuf::new(), 2);
})
.unwrap();

Expand Down Expand Up @@ -195,26 +196,7 @@ fn match_keys(groups: KeyStringGroups) -> (bool, KeyVkGroups) {
return (success, temp);
}

fn read_config(conf_path: &PathBuf) -> Vec<KeyVkGroups> {
//Default
let default_setting: Vec<KeyVkGroups> = Vec::from([
KeyVkGroups {
mod_keys: Vec::from([ModKey::Win, ModKey::Alt]),
vkey: VKey::V,
},
KeyVkGroups {
mod_keys: Vec::from([ModKey::Win, ModKey::Alt]),
vkey: VKey::C,
},
KeyVkGroups {
mod_keys: Vec::from([ModKey::Win, ModKey::Ctrl, ModKey::Shift]),
vkey: VKey::Escape,
},
KeyVkGroups {
mod_keys: Vec::from([ModKey::Ctrl, ModKey::Alt]),
vkey: VKey::O,
},
]);
fn read_config(conf_path: &PathBuf, default_settings: &Vec<KeyVkGroups>) -> Vec<KeyVkGroups> {
//读取配置
let mut f = File::open(conf_path).unwrap();
let mut full_content = String::new();
Expand Down Expand Up @@ -245,7 +227,7 @@ fn read_config(conf_path: &PathBuf) -> Vec<KeyVkGroups> {
if status {
result_groups.push(result);
} else {
result_groups.push(default_setting[count].clone());
result_groups.push(default_settings[count].clone());
}
count += 1;
}
Expand All @@ -268,10 +250,33 @@ fn main() {
//println!("{:?}", &exist_result);
unzip_res(&path_infos, &exist_result);

//Default
let default_setting: Vec<KeyVkGroups> = Vec::from([
KeyVkGroups {
mod_keys: Vec::from([ModKey::Win, ModKey::Alt]),
vkey: VKey::V,
},
KeyVkGroups {
mod_keys: Vec::from([ModKey::Win, ModKey::Alt]),
vkey: VKey::C,
},
KeyVkGroups {
mod_keys: Vec::from([ModKey::Win, ModKey::Ctrl, ModKey::Shift]),
vkey: VKey::Escape,
},
KeyVkGroups {
mod_keys: Vec::from([ModKey::Ctrl, ModKey::Alt]),
vkey: VKey::O,
},
]);
//Read Setting
let settings = read_config(&path_infos.conf_path);
let settings = read_config(&path_infos.conf_path, &default_setting);
println!("{:?}", &settings);
//Set Hotkeys
let handler = set_hotkeys(&path_infos.exe_path, &path_infos.conf_path, settings);
let handler = set_hotkeys(
&path_infos.exe_path,
&path_infos.conf_path,
settings,
);
handler.join().unwrap();
}

0 comments on commit 9281a49

Please sign in to comment.