fix opening files on macOS
This commit is contained in:
parent
420443dc59
commit
7b6dbf21c2
|
|
@ -126,17 +126,15 @@ fn handle_file_associations(app: AppHandle, files: Vec<PathBuf>) {
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
let pkg_name = env!("CARGO_PKG_NAME").to_string();
|
let pkg_name = env!("CARGO_PKG_NAME").to_string();
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
|
.manage(Mutex::new(AppState::default()))
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
{
|
|
||||||
app.manage(Mutex::new(AppState::default()));
|
|
||||||
}
|
|
||||||
#[cfg(any(windows, target_os = "linux"))] // Windows/Linux needs different handling from macOS
|
#[cfg(any(windows, target_os = "linux"))] // Windows/Linux needs different handling from macOS
|
||||||
{
|
{
|
||||||
let mut files = Vec::new();
|
let mut files = Vec::new();
|
||||||
|
|
||||||
// NOTICE: `args` may include URL protocol (`your-app-protocol://`)
|
// NOTICE: `args` may include URL protocol (`your-app-protocol://`)
|
||||||
// or arguments (`--`) if your app supports them.
|
// or arguments (`--`) if your app supports them.
|
||||||
// files may aslo be passed as `file://path/to/file`
|
// files may also be passed as `file://path/to/file`
|
||||||
for maybe_file in std::env::args().skip(1) {
|
for maybe_file in std::env::args().skip(1) {
|
||||||
// skip flags like -f or --flag
|
// skip flags like -f or --flag
|
||||||
if maybe_file.starts_with('-') {
|
if maybe_file.starts_with('-') {
|
||||||
|
|
@ -199,12 +197,21 @@ pub fn run() {
|
||||||
|app, event| {
|
|app, event| {
|
||||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
if let tauri::RunEvent::Opened { urls } = event {
|
if let tauri::RunEvent::Opened { urls } = event {
|
||||||
|
let app = app.clone();
|
||||||
let files = urls
|
let files = urls
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|url| url.to_file_path().ok())
|
.filter_map(|url| url.to_file_path().ok())
|
||||||
|
.map(|f| {
|
||||||
|
let file = f.to_string_lossy().replace('\\', "\\\\"); // escape backslash
|
||||||
|
format!("\"{file}\"",) // wrap in quotes for JS array
|
||||||
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
handle_file_associations(app.clone(), files);
|
tauri::async_runtime::spawn(async move {
|
||||||
|
for path in files {
|
||||||
|
create_window(app.clone(), Some(path)).await;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -7896,6 +7896,11 @@ async function renderMenu() {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
action: () => {},
|
action: () => {},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
text: "Close Window",
|
||||||
|
enabled: true,
|
||||||
|
action: quit,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
text: "Quit Lightningbeam",
|
text: "Quit Lightningbeam",
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue