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

View File

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

View File

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

View File

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