Make file opening work properly

This commit is contained in:
Skyler Lehmkuhl 2025-01-17 21:27:15 -05:00
parent 6e4f3d670f
commit f642fa8e4d
4 changed files with 12 additions and 10 deletions

View File

@ -4,7 +4,7 @@ use tauri_plugin_log::{Target, TargetKind};
use log::{trace, info, debug, warn, error};
use tracing_subscriber::EnvFilter;
use chrono::Local;
use tauri::{webview, AppHandle, Manager, Url, WebviewUrl, WebviewWindowBuilder};
use tauri::{AppHandle, Manager, Url, WebviewUrl, WebviewWindowBuilder};
#[derive(Default)]
@ -96,14 +96,14 @@ fn handle_file_associations(app: AppHandle, files: Vec<PathBuf>) {
let fs_scope = app.fs_scope();
// This is for the `asset:` protocol to work:
// let asset_protocol_scope = app.asset_protocol_scope();
let asset_protocol_scope = app.asset_protocol_scope();
for file in &files {
// This requires the `fs` plugin:
let _ = fs_scope.allow_file(file);
// This is for the `asset:` protocol:
// let _ = asset_protocol_scope.allow_file(file);
let _ = asset_protocol_scope.allow_file(file);
}
// -- Scope handling end --
@ -118,13 +118,8 @@ fn handle_file_associations(app: AppHandle, files: Vec<PathBuf>) {
.join(",");
warn!("{}",files);
// tauri::WebviewWindowBuilder::new(&app, "main", Default::default())
// .initialization_script(&format!("window.openedFiles = [{files}]"))
// .build()
// .unwrap();
let window = app.get_webview_window("main").unwrap();
window.eval(&format!("window.openedFiles = [{files}]")).unwrap();
// window.emit("openedFiles", &format!("[{files}]")).unwrap();
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]

View File

@ -17,7 +17,10 @@
}
],
"security": {
"csp": null
"csp": null,
"assetProtocol": {
"enable": true
}
}
},
"bundle": {

View File

@ -6705,7 +6705,9 @@ function outliner(object = undefined) {
async function startup() {
await loadConfig();
createNewFileDialog(_newFile, _open, config);
showNewFileDialog(config);
if (!window.openedFiles) {
showNewFileDialog(config);
}
}
startup();

View File

@ -145,12 +145,14 @@ function createNewFileDialog(newFileCallback, openFileCallback, config) {
}
function showNewFileDialog(config) {
if (!overlay) return;
overlay.style.display = 'block';
newFileDialog.style.display = 'block';
displayFiles(config.recentFiles); // Reload the recent files
}
function closeDialog() {
if (!overlay) return;
overlay.style.display = 'none';
newFileDialog.style.display = 'none';
}