Skip to content

Commit

Permalink
update hotkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikachu2333 authored Dec 8, 2024
1 parent af35943 commit 0ce8b78
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "SC_Starter"
version = "1.8.0"
version = "1.9.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -13,7 +13,7 @@ panic = "abort"

[dependencies]
directories = "5.0.1"
rust-embed = { version = "8.4.0", default-features = false, features = [
rust-embed = { version = "8.5.0", default-features = false, features = [
"compression",
] }
single-instance = "0.3.3"
Expand Down
37 changes: 26 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
io::Read,
os::windows::{fs::MetadataExt, process::CommandExt},
path::{Path, PathBuf},
process::{exit, Command},
process::Command,
thread::{self, JoinHandle},
};
use windows_hotkeys::{
Expand Down Expand Up @@ -91,8 +91,8 @@ fn check_exe_latest(file_path: &Path) -> bool {
in_size == RES_SIZE
}

///解压相关资源
fn unzip_res(paths: &PathInfos, exists: &FileExist) {
//解压相关资源
#[derive(Embed)]
#[folder = "res/"]
struct Asset;
Expand Down Expand Up @@ -130,7 +130,10 @@ fn operate_exe(path: &Path, mode: usize) {
1 => {
let _ = Command::new(path).arg("--pin:clipboard").spawn().unwrap();
}
2 => exit(0),
2 => {
println!("Exit");
std::process::exit(0)
}
3 => {
let _ = Command::new("explorer.exe").arg(path).spawn().unwrap();
}
Expand Down Expand Up @@ -158,7 +161,10 @@ fn set_hotkeys(paths: &PathInfos, key_groups: Vec<KeyVkGroups>) -> JoinHandle<()
});
match hotkey_1 {
Ok(_) => (),
Err(_) => panic!("Failed reg Hotkey 1."),
Err(_) => {
operate_exe(&conf_path, 3);
panic!("Failed reg Hotkey 1.")
}
};

let hotkey_2 = hkm.register(key_groups[1].vkey, &key_groups[1].mod_keys, move || {
Expand All @@ -177,10 +183,15 @@ fn set_hotkeys(paths: &PathInfos, key_groups: Vec<KeyVkGroups>) -> JoinHandle<()
Err(_) => panic!("Failed reg Hotkey 3."),
}

hkm.register(key_groups[3].vkey, &key_groups[3].mod_keys, move || {
let hotkey_4 = hkm.register(key_groups[3].vkey, &key_groups[3].mod_keys, move || {
operate_exe(&conf_path, 3);
})
.unwrap();
});
match hotkey_4 {
Ok(_) => (),
Err(_) => {
panic!("Failed reg Hotkey 4.")
}
}

hkm.event_loop();
})
Expand Down Expand Up @@ -299,19 +310,23 @@ fn main() {
//Default
let default_setting: Vec<KeyVkGroups> = Vec::from([
KeyVkGroups {
mod_keys: Vec::from([ModKey::Win, ModKey::Alt]),
vkey: VKey::V,
//PrintScreen
mod_keys: Vec::from([ModKey::Win, ModKey::Alt, ModKey::Ctrl]),
vkey: VKey::P,
},
KeyVkGroups {
mod_keys: Vec::from([ModKey::Win, ModKey::Alt]),
//Pin
mod_keys: Vec::from([ModKey::Win, ModKey::Alt, ModKey::Ctrl]),
vkey: VKey::C,
},
KeyVkGroups {
//Exit
mod_keys: Vec::from([ModKey::Win, ModKey::Ctrl, ModKey::Shift]),
vkey: VKey::Escape,
},
KeyVkGroups {
mod_keys: Vec::from([ModKey::Ctrl, ModKey::Alt]),
//OpenSettings
mod_keys: Vec::from([ModKey::Win, ModKey::Alt, ModKey::Ctrl]),
vkey: VKey::O,
},
]);
Expand Down

0 comments on commit 0ce8b78

Please sign in to comment.