Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.

Commit 656bd69

Browse files
author
Snazzie
committed
move js out of rs so it is easier edit and code scan
1 parent 0e10db5 commit 656bd69

File tree

11 files changed

+603
-548
lines changed

11 files changed

+603
-548
lines changed

src-tauri/build.rs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,69 @@
1+
use std::env;
2+
use std::fs;
3+
use std::path::{Path, PathBuf};
4+
15
fn main() {
2-
tauri_build::build()
6+
import_js_scripts_to_rust();
7+
8+
// Run the Tauri build process
9+
tauri_build::build();
10+
}
11+
12+
/// Imports JavaScript file contents to Rust string constants
13+
///
14+
/// This function handles the entire process of:
15+
/// 1. Locating the JavaScript files
16+
/// 2. Reading their contents
17+
/// 3. Generating Rust code with the JS content as string constants
18+
/// 4. Writing the generated code to the output file
19+
///
20+
/// # Returns
21+
///
22+
/// The path to the generated Rust file
23+
fn import_js_scripts_to_rust() -> PathBuf {
24+
// Get the output directory for generated files
25+
let out_dir = env::var("OUT_DIR").unwrap();
26+
let dest_path = Path::new(&out_dir).join("js_scripts.rs");
27+
28+
// Get the manifest directory (where Cargo.toml is located)
29+
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
30+
let js_dir = Path::new(&manifest_dir)
31+
.join("src")
32+
.join("scripts")
33+
.join("js");
34+
35+
// Define the scripts to compile
36+
let scripts = [
37+
("FULLSCREEN_SCRIPT", "fullscreen_script.js"),
38+
("PIP_SCRIPT", "pip_script.js"),
39+
("PIP_OVERLAY_SCRIPT", "pip_overlay_script.js"),
40+
("ZOOM_SCRIPT", "zoom_script.js"),
41+
];
42+
43+
// Generate Rust code for each script
44+
let mut rust_code = String::new();
45+
46+
for (const_name, js_filename) in scripts.iter() {
47+
// Create the full path to the JS file
48+
let js_path: PathBuf = js_dir.join(js_filename);
49+
50+
// Read the JS file content
51+
let js_content = fs::read_to_string(&js_path)
52+
.expect(&format!("Failed to read JS file: {}", js_path.display()));
53+
54+
// Add the constant definition to the Rust code
55+
rust_code.push_str(&format!(
56+
"pub const {}: &str = r#\"\n{}\n\"#;\n\n",
57+
const_name, js_content
58+
));
59+
60+
// Tell Cargo to rerun the build script if this JS file changes
61+
println!("cargo:rerun-if-changed={}", js_path.display());
62+
}
63+
64+
// Write the generated Rust code to the output file
65+
fs::write(&dest_path, rust_code).expect("Failed to write generated Rust code");
66+
67+
// Return the path to the generated file
68+
dest_path
369
}

src-tauri/src/scripts/fullscreen_script.rs

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Add a fullscreen change event listener to the document
2+
document.addEventListener('fullscreenchange', function(event) {
3+
// Check if the document is in fullscreen mode
4+
const isFullscreen = document.fullscreenElement !== null;
5+
console.log('Fullscreen event detected!', event);
6+
console.log('Fullscreen state:', isFullscreen);
7+
console.log('Fullscreen element:', document.fullscreenElement);
8+
9+
// Send a message to the Tauri app using the invoke system
10+
try {
11+
if (window.__TAURI_INTERNALS__) {
12+
// Safely get the current window label
13+
let windowLabel = null;
14+
try {
15+
// Check if metadata and currentWindow exist
16+
if (window.__TAURI_INTERNALS__.metadata &&
17+
window.__TAURI_INTERNALS__.metadata.currentWindow) {
18+
windowLabel = window.__TAURI_INTERNALS__.metadata.currentWindow.label;
19+
console.log('Current window label:', windowLabel);
20+
} else {
21+
console.log('Window metadata not available for fullscreen event, using null window label');
22+
}
23+
} catch (metadataErr) {
24+
console.warn('Could not access window metadata for fullscreen event:', metadataErr);
25+
}
26+
27+
// Directly invoke the toggle_fullscreen command with window label
28+
window.__TAURI_INTERNALS__.invoke('toggle_fullscreen', {
29+
isFullscreen: isFullscreen,
30+
windowLabel: windowLabel
31+
});
32+
console.log('Invoked toggle_fullscreen with state:', isFullscreen, 'for window:', windowLabel);
33+
} else {
34+
console.error('__TAURI_INTERNALS__ is not available');
35+
}
36+
} catch (e) {
37+
console.error('Error invoking toggle_fullscreen:', e);
38+
}
39+
});

0 commit comments

Comments
 (0)