mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-04-27 11:56:05 +02:00
fe79adb5c7
* feat: scaffold NFC plugin, initial iOS code * adjust script paths (api example) * update entitlements & plist * update class name * update api * sketch api, remove desktop * update response data * add write fn * remove commands * fixes for write mode * check nfc state before using the APIs * fix(example): downgrade internal-ip to v7 * feat: typed iOS arguments * update swift requirement * android updates * update tauri * fix icon * update example * fix build * fix notification example * fix clipboard * fix ios notification build * fix info.plist * update tauri * add change file * fmt * update to new args class syntax :( [skip ci] * add lang code handling in RTD_TEXT helper (written payload is broken without it) * update nfc to latest tauri. use tauri from git * update lockfile * android: add initial nfc writer implementation * check sdk version for pendingintent flag * quicksaving basic ndef reading that doesn't crash * add basic ndef reading (android) * small cleanup * change pending action type * validate available state * gradle 8.0.0 * use session class * implement keep session alive * fix notification crash?? * remove dox feature, fix breaking changes * update dependencies * fix shell tests [skip ci] * fmt [skip ci] * type safe args * scan kind options * commit .idea files * update api * update example * fix app check * alertmessage options for iOS * default to tag on example * fix(ios): always close session on write, remove keepsessionalive option * add kind input to write options * empty records if message not found * fill tag metadata for ndef read * add contributors * update vite * covector setup * tauri/dox removed * docs and examples * fmt [skip ci] --------- Co-authored-by: FabianLars-crabnebula <fabianlars@crabnebula.dev> Co-authored-by: Lucas Nogueira <lucas@tauri.app> Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
149 lines
5.0 KiB
Rust
149 lines
5.0 KiB
Rust
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
mod cmd;
|
|
#[cfg(desktop)]
|
|
mod tray;
|
|
|
|
use serde::Serialize;
|
|
use tauri::{window::WindowBuilder, App, AppHandle, Manager, RunEvent, WindowUrl};
|
|
|
|
#[derive(Clone, Serialize)]
|
|
struct Reply {
|
|
data: String,
|
|
}
|
|
|
|
pub type SetupHook = Box<dyn FnOnce(&mut App) -> Result<(), Box<dyn std::error::Error>> + Send>;
|
|
pub type OnEvent = Box<dyn FnMut(&AppHandle, RunEvent)>;
|
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
|
pub fn run() {
|
|
#[allow(unused_mut)]
|
|
let mut builder = tauri::Builder::default()
|
|
.plugin(
|
|
tauri_plugin_log::Builder::default()
|
|
.level(log::LevelFilter::Info)
|
|
.build(),
|
|
)
|
|
.plugin(tauri_plugin_fs::init())
|
|
.plugin(tauri_plugin_clipboard_manager::init())
|
|
.plugin(tauri_plugin_dialog::init())
|
|
.plugin(tauri_plugin_http::init())
|
|
.plugin(tauri_plugin_notification::init())
|
|
.plugin(tauri_plugin_os::init())
|
|
.plugin(tauri_plugin_process::init())
|
|
.plugin(tauri_plugin_shell::init())
|
|
.setup(move |app| {
|
|
#[cfg(desktop)]
|
|
{
|
|
tray::create_tray(app.handle())?;
|
|
app.handle().plugin(tauri_plugin_cli::init())?;
|
|
app.handle()
|
|
.plugin(tauri_plugin_global_shortcut::Builder::new().build())?;
|
|
app.handle()
|
|
.plugin(tauri_plugin_updater::Builder::new().build())?;
|
|
}
|
|
#[cfg(mobile)]
|
|
{
|
|
app.handle().plugin(tauri_plugin_barcode_scanner::init())?;
|
|
app.handle().plugin(tauri_plugin_nfc::init())?;
|
|
}
|
|
|
|
let mut window_builder = WindowBuilder::new(app, "main", WindowUrl::default());
|
|
#[cfg(desktop)]
|
|
{
|
|
window_builder = window_builder
|
|
.user_agent(&format!("Tauri API - {}", std::env::consts::OS))
|
|
.title("Tauri API Validation")
|
|
.inner_size(1000., 800.)
|
|
.min_inner_size(600., 400.)
|
|
.content_protected(true);
|
|
}
|
|
|
|
#[cfg(target_os = "windows")]
|
|
{
|
|
window_builder = window_builder
|
|
.transparent(true)
|
|
.shadow(true)
|
|
.decorations(false);
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
|
{
|
|
window_builder = window_builder.transparent(true);
|
|
}
|
|
|
|
let window = window_builder.build().unwrap();
|
|
|
|
#[cfg(debug_assertions)]
|
|
window.open_devtools();
|
|
|
|
#[cfg(desktop)]
|
|
std::thread::spawn(|| {
|
|
let server = match tiny_http::Server::http("localhost:3003") {
|
|
Ok(s) => s,
|
|
Err(e) => {
|
|
eprintln!("{}", e);
|
|
std::process::exit(1);
|
|
}
|
|
};
|
|
loop {
|
|
if let Ok(mut request) = server.recv() {
|
|
let mut body = Vec::new();
|
|
let _ = request.as_reader().read_to_end(&mut body);
|
|
let response = tiny_http::Response::new(
|
|
tiny_http::StatusCode(200),
|
|
request.headers().to_vec(),
|
|
std::io::Cursor::new(body),
|
|
request.body_length(),
|
|
None,
|
|
);
|
|
let _ = request.respond(response);
|
|
}
|
|
}
|
|
});
|
|
|
|
Ok(())
|
|
})
|
|
.on_page_load(|window, _| {
|
|
let window_ = window.clone();
|
|
window.listen("js-event", move |event| {
|
|
println!("got js-event with message '{:?}'", event.payload());
|
|
let reply = Reply {
|
|
data: "something else".to_string(),
|
|
};
|
|
|
|
window_
|
|
.emit("rust-event", Some(reply))
|
|
.expect("failed to emit");
|
|
});
|
|
});
|
|
|
|
#[cfg(target_os = "macos")]
|
|
{
|
|
builder = builder.menu(tauri::menu::Menu::default);
|
|
}
|
|
|
|
#[allow(unused_mut)]
|
|
let mut app = builder
|
|
.invoke_handler(tauri::generate_handler![
|
|
cmd::log_operation,
|
|
cmd::perform_request,
|
|
])
|
|
.build(tauri::tauri_build_context!())
|
|
.expect("error while building tauri application");
|
|
|
|
#[cfg(target_os = "macos")]
|
|
app.set_activation_policy(tauri::ActivationPolicy::Regular);
|
|
|
|
app.run(move |_app_handle, _event| {
|
|
#[cfg(desktop)]
|
|
if let RunEvent::ExitRequested { api, .. } = &_event {
|
|
// Keep the event loop running even if all windows are closed
|
|
// This allow us to catch system tray events when there is no window
|
|
api.prevent_exit();
|
|
}
|
|
})
|
|
}
|