Init Commit
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
use tauri::{
|
||||
menu::{Menu, MenuItem},
|
||||
tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
|
||||
Manager, WebviewUrl, WebviewWindowBuilder, WindowEvent,
|
||||
};
|
||||
|
||||
const INJECT_JS: &str = include_str!("../../src/inject.js");
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.setup(|app| {
|
||||
let show = MenuItem::with_id(app, "show", "Open", true, None::<&str>)?;
|
||||
let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
|
||||
let menu = Menu::with_items(app, &[&show, &quit])?;
|
||||
let url = WebviewUrl::External("https://helpalert.wvumedicine.org".parse().unwrap());
|
||||
let w_handle = app.handle().clone();
|
||||
WebviewWindowBuilder::new(app, "main", url)
|
||||
.title("WVU Medicine Help Alert")
|
||||
.inner_size(1200.0, 1000.0)
|
||||
.initialization_script(INJECT_JS)
|
||||
.on_navigation(move |nav_url| {
|
||||
if nav_url.path().contains("helpalert.html") {
|
||||
if let Some(w) = w_handle.get_webview_window("main") {
|
||||
let _ = w.eval(
|
||||
"document.documentElement.innerHTML = \
|
||||
'<head><style>*{margin:0;padding:0}html,body{height:100%;overflow:hidden}iframe{width:100%;height:100%;border:none}</style></head>' + \
|
||||
'<body><iframe src=\"https://helpalert.wvumedicine.org/PinPoint/helpalert.html\"></iframe></body>';"
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
true
|
||||
})
|
||||
.build()?;
|
||||
TrayIconBuilder::new()
|
||||
.tooltip("WVUMedicine Help Alert Web Client")
|
||||
.menu(&menu)
|
||||
.icon(app.default_window_icon().unwrap().clone())
|
||||
.on_menu_event(|app, event| match event.id.as_ref() {
|
||||
"show" => {
|
||||
if let Some(w) = app.get_webview_window("main") {
|
||||
let _ = w.show();
|
||||
let _ = w.set_focus();
|
||||
}
|
||||
}
|
||||
"quit" => {
|
||||
app.exit(0);
|
||||
}
|
||||
_ => {}
|
||||
})
|
||||
.on_tray_icon_event(|tray, event| {
|
||||
if let TrayIconEvent::Click {
|
||||
button: MouseButton::Left,
|
||||
button_state: MouseButtonState::Down,
|
||||
..
|
||||
} = event
|
||||
{
|
||||
if let Some(w) = tray.app_handle().get_webview_window("main") {
|
||||
let _ = w.show();
|
||||
let _ = w.set_focus();
|
||||
}
|
||||
}
|
||||
})
|
||||
.build(app)?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|window, event| {
|
||||
if let WindowEvent::CloseRequested { api, .. } = event {
|
||||
api.prevent_close();
|
||||
let _ = window.hide();
|
||||
}
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
duress_lib::run()
|
||||
}
|
||||
Reference in New Issue
Block a user