first commit

This commit is contained in:
vitalii.litvinchuk
2026-09-18 09:42:16 +03:00
commit ac827c492f
41 changed files with 7178 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
+205
View File
@@ -0,0 +1,205 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use std::fs;
use std::path::PathBuf;
use tauri::AppHandle;
use tauri::{
menu::{Menu, MenuItem},
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
Manager,
};
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt, Modifiers, Shortcut, ShortcutState};
use windows_icons::{get_icon_base64_by_path_with_size, IconSize};
#[derive(serde::Serialize)]
pub struct AppItem {
name: String,
path: String,
source: String,
}
#[tauri::command]
fn get_apps() -> Vec<AppItem> {
let mut apps = Vec::new();
if let Some(mut path) = dirs::data_dir() {
path.push("Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar");
if let Ok(entries) = std::fs::read_dir(&path) {
for entry in entries.flatten() {
let file_path = entry.path();
if file_path.extension().unwrap_or_default() == "lnk" {
let name = file_path
.file_stem()
.unwrap_or_default()
.to_string_lossy()
.to_string();
apps.push(AppItem {
name,
path: file_path.to_string_lossy().to_string(),
source: "Taskbar".to_string(),
});
}
}
}
}
if let Some(mut path) = dirs::data_dir() {
path.push("Microsoft\\Windows\\Start Menu\\Programs");
if let Ok(entries) = std::fs::read_dir(&path) {
for entry in entries.flatten() {
let file_path = entry.path();
if file_path.extension().unwrap_or_default() == "lnk" {
let name = file_path
.file_stem()
.unwrap_or_default()
.to_string_lossy()
.to_string();
apps.push(AppItem {
name,
path: file_path.to_string_lossy().to_string(),
source: "Start Menu".to_string(),
});
}
}
}
}
apps
}
#[tauri::command]
fn launch_app(path: String) -> Result<(), String> {
open::that(path).map_err(|e| e.to_string())
}
fn pinned_file(app: &AppHandle) -> Result<PathBuf, String> {
let dir = app.path().app_data_dir().map_err(|e| e.to_string())?;
fs::create_dir_all(&dir).map_err(|e| e.to_string())?;
Ok(dir.join("pinned.json"))
}
#[tauri::command]
fn get_pinned_apps(app: AppHandle) -> Result<Vec<String>, String> {
let path = pinned_file(&app)?;
if !path.exists() {
return Ok(Vec::new());
}
let data = fs::read_to_string(&path).map_err(|e| e.to_string())?;
serde_json::from_str(&data).map_err(|e| e.to_string())
}
#[tauri::command]
fn set_pinned_apps(app: AppHandle, paths: Vec<String>) -> Result<(), String> {
let path = pinned_file(&app)?;
let data = serde_json::to_string_pretty(&paths).map_err(|e| e.to_string())?;
fs::write(&path, data).map_err(|e| e.to_string())
}
#[tauri::command]
fn get_app_icon(path: String) -> Result<String, String> {
#[cfg(target_os = "windows")]
{
let result = get_icon_base64_by_path_with_size(&path, IconSize::Large)
.or_else(|_| windows_icons::get_icon_base64_by_path(&path));
match result {
Ok(b64) => {
if b64.starts_with("data:") {
Ok(b64)
} else {
Ok(format!("data:image/png;base64,{}", b64))
}
}
Err(_) => Ok(String::new()),
}
}
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
get_apps,
launch_app,
get_pinned_apps,
set_pinned_apps,
get_app_icon
])
.plugin(
tauri_plugin_autostart::Builder::new()
.args(["--autostart"])
.app_name("App Launcher")
.build(),
)
.plugin(
tauri_plugin_global_shortcut::Builder::new()
.with_handler(|app, shortcut, event| {
if event.state == ShortcutState::Pressed {
if shortcut.matches(Modifiers::ALT, Code::Space) {
if let Some(window) = app.get_webview_window("main") {
let is_visible = window.is_visible().unwrap_or(false);
if is_visible {
window.hide().unwrap();
} else {
window.show().unwrap();
window.set_focus().unwrap();
}
}
}
}
})
.build(),
)
.setup(|app| {
let alt_space = Shortcut::new(Some(Modifiers::ALT), Code::Space);
app.global_shortcut().register(alt_space)?;
let show_i = MenuItem::with_id(app, "show", "Показати/Сховати", true, None::<&str>)?;
let quit_i = MenuItem::with_id(app, "quit", "Вийти", true, None::<&str>)?;
let menu = Menu::with_items(app, &[&show_i, &quit_i])?;
TrayIconBuilder::new()
.icon(app.default_window_icon().unwrap().clone())
.menu(&menu)
.show_menu_on_left_click(false)
.on_tray_icon_event(|tray, event| match event {
TrayIconEvent::Click {
button: MouseButton::Left,
button_state: MouseButtonState::Up,
..
} => {
let app_handle = tray.app_handle();
if let Some(window) = app_handle.get_webview_window("main") {
let is_visible = window.is_visible().unwrap_or(false);
if is_visible {
window.hide().unwrap();
} else {
window.show().unwrap();
window.set_focus().unwrap();
}
}
}
_ => {}
})
.on_menu_event(|app_handle, event| match event.id.as_ref() {
"quit" => std::process::exit(0),
"show" => {
if let Some(window) = app_handle.get_webview_window("main") {
let is_visible = window.is_visible().unwrap_or(false);
if is_visible {
window.hide().unwrap();
} else {
window.show().unwrap();
window.set_focus().unwrap();
}
}
}
_ => {}
})
.build(app)?;
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}