Multi-platform support!

This commit is contained in:
Elizabeth Cray 2023-07-23 18:32:43 -04:00
parent 49b11741cb
commit ac2f526d8a
3 changed files with 70 additions and 14 deletions

View File

@ -24,15 +24,40 @@ fn type_str(input: String) {
// Load input into clipboard // Load input into clipboard
clipboard.set_text(input).unwrap(); clipboard.set_text(input).unwrap();
// TODO: Multi-platform window switch // TODO: Set the Command/Alt key configured by user
enigo.key_down(Key::Alt); #[cfg(target_os = "macos")] {
enigo.key_click(Key::Tab); enigo.key_down(Key::Command);
enigo.key_up(Key::Alt); enigo.key_click(Key::Tab);
enigo.key_up(Key::Command);
}
#[cfg(target_os = "windows")] {
enigo.key_down(Key::Alt);
enigo.key_click(Key::Tab);
enigo.key_up(Key::Alt);
}
#[cfg(target_os = "linux")] {
enigo.key_down(Key::Alt);
enigo.key_click(Key::Tab);
enigo.key_up(Key::Alt);
}
thread::sleep(Duration::from_millis(200)); thread::sleep(Duration::from_millis(200));
// TODO: Multi-platform paste #[cfg(target_os = "windows")]{
#[cfg(not(dev))]{ enigo.key_down(Key::Control);
enigo.key_click(Key::Layout('v'));
enigo.key_up(Key::Control);
}
#[cfg(target_os = "macos")]{
enigo.key_down(Key::Command);
enigo.key_click(Key::Layout('v'));
enigo.key_up(Key::Command);
}
#[cfg(target_os = "linux")]{
enigo.key_down(Key::Control); enigo.key_down(Key::Control);
enigo.key_click(Key::Layout('v')); enigo.key_click(Key::Layout('v'));
enigo.key_up(Key::Control); enigo.key_up(Key::Control);
@ -47,7 +72,6 @@ fn type_str(input: String) {
} }
fn main() { fn main() {
// TODO: Set Window location on launch
tauri::Builder::default() tauri::Builder::default()
.plugin(tauri_plugin_positioner::init()) .plugin(tauri_plugin_positioner::init())
.invoke_handler(tauri::generate_handler![type_str, get_mouse_pos]) .invoke_handler(tauri::generate_handler![type_str, get_mouse_pos])

View File

@ -18,11 +18,23 @@
"sidecar": true, "sidecar": true,
"execute": true, "execute": true,
"open": true, "open": true,
"scope": [{ "scope": [
"name" : "open-link", {
"cmd": "powershell.exe", "name" : "open-link-win",
"args": ["-Command", "Start-Process", {"validator": "\\S+"}] "cmd": "powershell.exe",
}] "args": ["-Command", "Start-Process", {"validator": "\\S+"}]
},
{
"name" : "open-link-linux",
"cmd": "/bin/sh",
"args": ["-c", "xdg-open", {"validator": "\\S+"}]
},
{
"name" : "open-link-macos",
"cmd": "/bin/bash",
"args": ["-c", "open", {"validator": "\\S+"}]
}
]
}, },
"fs": { "fs": {
"all": true, "all": true,
@ -30,6 +42,9 @@
}, },
"path": { "path": {
"all": true "all": true
},
"os": {
"all": true
} }
}, },
"bundle": { "bundle": {

View File

@ -3,6 +3,7 @@ import { resolveResource } from "@tauri-apps/api/path";
import { readTextFile } from "@tauri-apps/api/fs"; import { readTextFile } from "@tauri-apps/api/fs";
import { invoke } from '@tauri-apps/api/tauri' import { invoke } from '@tauri-apps/api/tauri'
import Modal from "react-modal"; import Modal from "react-modal";
import { platform } from '@tauri-apps/api/os';
import "./App.css"; import "./App.css";
import { Command } from '@tauri-apps/api/shell' import { Command } from '@tauri-apps/api/shell'
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@ -168,8 +169,24 @@ function App() {
<div className="row modal-footer"> <div className="row modal-footer">
<div className="col-4" onClick={() => { <div className="col-4" onClick={() => {
let url = "https://git.corrupt.link/liz/AllenWrench"; let url = "https://git.corrupt.link/liz/AllenWrench";
// TODO: Make multi-platform platform().then((os: string) => {
new Command("open-link", ["-Command", "Start-Process", `${url}`]).spawn(); switch(os) {
case "win32":
new Command("open-link-win", ["-Command", "Start-Process", `${url}`]).spawn();
break;
case "linux":
new Command("open-link-linux", ["-c", "xdg-open", `${url}`]).spawn();
break;
case "macos":
new Command("open-link-macos", ["-c", "open", `${url}`]).spawn();
break;
default:
console.log(`Unknown OS: ${os}`);
break;
}
});
}}> }}>
<FontAwesomeIcon className="icon" icon={faGitAlt} size="2x" /> <FontAwesomeIcon className="icon" icon={faGitAlt} size="2x" />
</div> </div>