|
1 | | -// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/ |
2 | 1 | mod plex_handler; |
3 | 2 |
|
4 | 3 | use plex_handler::toggle_fullscreen; |
5 | | - |
6 | | -#[tauri::command] |
7 | | -fn greet(name: &str) -> String { |
8 | | - format!("Hello, {}! You've been greeted from Rust!", name) |
9 | | -} |
| 4 | +mod script; |
10 | 5 |
|
11 | 6 | #[cfg_attr(mobile, tauri::mobile_entry_point)] |
12 | 7 | pub fn run() { |
13 | | - // Fullscreen event listener script |
14 | | - let init_script = " |
15 | | - // Add a fullscreen change event listener to the document |
16 | | - document.addEventListener('fullscreenchange', function(event) { |
17 | | - // Check if the document is in fullscreen mode |
18 | | - const isFullscreen = document.fullscreenElement !== null; |
19 | | - console.log('Fullscreen event detected!', event); |
20 | | - console.log('Fullscreen state:', isFullscreen); |
21 | | - console.log('Fullscreen element:', document.fullscreenElement); |
22 | | -
|
23 | | - // Send a message to the Tauri app using the invoke system |
24 | | - try { |
25 | | - if (window.__TAURI_INTERNALS__) { |
26 | | - // Get the current window label |
27 | | - const windowLabel = window.__TAURI_INTERNALS__.metadata.currentWindow.label; |
28 | | - console.log('Current window label:', windowLabel); |
29 | | -
|
30 | | - // Directly invoke the toggle_fullscreen command with window label |
31 | | - window.__TAURI_INTERNALS__.invoke('toggle_fullscreen', { |
32 | | - isFullscreen: isFullscreen, |
33 | | - windowLabel: windowLabel |
34 | | - }); |
35 | | - console.log('Invoked toggle_fullscreen with state:', isFullscreen, 'for window:', windowLabel); |
36 | | - } else { |
37 | | - console.error('__TAURI_INTERNALS__ is not available'); |
38 | | - } |
39 | | - } catch (e) { |
40 | | - console.error('Error invoking toggle_fullscreen:', e); |
41 | | - } |
42 | | - }); |
43 | | -
|
44 | | - console.log('Plex fullscreen event listener injected'); |
45 | | - "; |
46 | | - |
| 8 | + // Fullscreen event listener scrip |
47 | 9 | tauri::Builder::default() |
48 | 10 | .plugin(tauri_plugin_opener::init()) |
49 | 11 | .plugin(tauri_plugin_store::Builder::default().build()) |
50 | | - .invoke_handler(tauri::generate_handler![greet, toggle_fullscreen,]) |
51 | | - // Setup hook to inject the script into any new webview window |
52 | | - .setup(|_app| { |
53 | | - println!("Tauri application setup complete."); |
54 | | - Ok(()) |
55 | | - }) |
| 12 | + .invoke_handler(tauri::generate_handler![toggle_fullscreen,]) |
56 | 13 | // Use the initialization script for all webviews |
57 | | - .append_invoke_initialization_script(init_script) |
| 14 | + .append_invoke_initialization_script(script::INIT_SCRIPT) |
58 | 15 | .run(tauri::generate_context!()) |
59 | 16 | .expect("error while running tauri application"); |
60 | 17 | } |
0 commit comments