mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-05 10:13:00 +02:00
* fix(utils): fix resources map becomes directory closes #10187 Fixes the behavior of mapped resources generating extra directory, for example: `"../resources/user.json": "resources/user.json"` generates this resource `resources/user.json/user.json` where it should generate `resources/user.json` This PR includes a refactor of the Iterator implementation which splits it into more scoped functions and relis on recursing instead of a loop which makes the code a lot more readable and easier to maintain. * clippy * cover more cases * clippy * fix glob into directory, not resolving target correctly * return error when resource origin path doesn't exist * fix resources example build * Update .changes/resources-map-becoming-dirs.md --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
|
|
|
use std::{
|
|
io::{BufRead, BufReader},
|
|
process::{Command, Stdio},
|
|
};
|
|
use tauri::{Emitter, Manager};
|
|
|
|
fn main() {
|
|
tauri::Builder::default()
|
|
.setup(move |app| {
|
|
let window = app.get_webview_window("main").unwrap();
|
|
let script_path = app
|
|
.path()
|
|
.resolve("assets/index.js", tauri::path::BaseDirectory::Resource)
|
|
.unwrap()
|
|
.to_string_lossy()
|
|
.to_string();
|
|
std::thread::spawn(move || {
|
|
let mut child = Command::new("node")
|
|
.args(&[script_path])
|
|
.stdout(Stdio::piped())
|
|
.spawn()
|
|
.expect("Failed to spawn node");
|
|
let stdout = child.stdout.take().unwrap();
|
|
let mut stdout = BufReader::new(stdout);
|
|
|
|
let mut line = String::new();
|
|
loop {
|
|
let n = stdout.read_line(&mut line).unwrap();
|
|
if n == 0 {
|
|
break;
|
|
}
|
|
|
|
window
|
|
.emit("message", Some(format!("'{}'", line)))
|
|
.expect("failed to emit event");
|
|
|
|
line.clear();
|
|
}
|
|
});
|
|
|
|
Ok(())
|
|
})
|
|
.run(tauri::generate_context!())
|
|
.expect("error while running tauri application");
|
|
}
|