TouchAppli
TouchAppli est un micro-application en Rust pour gérer le choix d'une des applications ouvertes depuis un poste à écran tactile.
Généralité
Fichier source
package.json
{
"name": "touchappli",
"private": true,
"version": "0.1.0",
"type": "module",
"scripts": {
"tauri": "tauri"
},
"devDependencies": {
"@tauri-apps/cli": "^2"
}
}
main.rs
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
touchappli_lib::run()
}
lib.rs
use tauri::{Manager, PhysicalPosition};
use enigo::{Direction, Enigo, Key, Keyboard, Settings};
use std::{thread::sleep, time::Duration};
const PAUSE: Duration = Duration::from_millis(3000);
fn nouvel_enigo() -> Result<Enigo, String> {
Enigo::new(&Settings::default()).map_err(|e| e.to_string())
}
/// Alt + Tab (passer à la fenêtre suivante)
#[tauri::command]
fn alt_tab() -> Result<(), String> {
let mut e = nouvel_enigo()?;
e.key(Key::Alt, Direction::Press).map_err(|x| x.to_string())?;
e.key(Key::Tab, Direction::Press).map_err(|x| x.to_string())?;
sleep(PAUSE);
Ok(())
}
/// Windows + D (afficher le bureau)
#[tauri::command]
fn win_d() -> Result<(), String> {
let mut e = nouvel_enigo()?;
e.key(Key::Meta, Direction::Press).map_err(|x| x.to_string())?;
e.key(Key::Unicode('d'), Direction::Press).map_err(|x| x.to_string())?;
sleep(PAUSE);
Ok(())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.setup(|app| {
let window = app.get_webview_window("main").unwrap();
let monitor = window.primary_monitor().unwrap().unwrap();
let screen = monitor.size();
let win_size = window.outer_size().unwrap();
let x = ((screen.width - win_size.width) / 2) as i32; // calcul du centre de l écran
let y = 0 as i32; // marge en haut (utile si pas de decoration)
window.set_position(PhysicalPosition::new(x, y)).unwrap();
Ok(())
})
.invoke_handler(tauri::generate_handler![alt_tab, win_d])
.run(tauri::generate_context!())
.expect("erreur au lancement de l'application Tauri");
}
index.html
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<title>Simulateur de raccourcis</title>
<style>
body {
font-family: system-ui, sans-serif;
display: flex;
justify-content: center;
margin: auto;
background-color: #8b8;
color: #eee;
}
header {
display: flex;
flex-direction: row;
gap: 2em;
padding: 2px;
}
button {
margin:1;
padding: 9px 8px;
min-width: 13em;
font-size: 1.1em;
border: none;
border-radius: 8px;
cursor: pointer;
background: #0f3460;
color: #e0e0e0;
transition: background .2s;
}
button:hover {
background: #1a5276;
}
button:active {
background: #2980b9;
}
.poignee {
font-size: 1.5em;
color: black;
margin: 0 .6em;
padding: 0 .4em;
border-radius: 6px;
cursor: move;
}
.poignee:hover {
background: #aba;
}
</style>
<script type="module">
const { invoke } = window.__TAURI__.core;
document.getElementById('btn-alt-tab').addEventListener('click', () => { invoke('alt_tab'); });
document.getElementById('btn-win-d').addEventListener('click', () => { invoke('win_d'); });
</script>
</head>
<body>
<header>
<span class="poignee">: : :</span>
<button id="btn-alt-tab" title="Vers autre fenêtre ou programme">Changement de fenêtre</button>
<button id="btn-win-d" title="Bascule du bureau">Affichage du bureau</button>
<span class="poignee">: : :</span>
</header>
</body>
</html>
main.js
néant
styles.css
néant