fix: file theme import by association file

This commit is contained in:
HorizonCode committed 2026-05-21 14:26:16 +02:00
1 parent a1f96a7de3
commit bde922ab9f
3 files changed
+67 -34

No files matched your search

+28 -13
View File
@@ -2,6 +2,7 @@
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Mutex; use std::sync::Mutex;
use tauri::Manager; use tauri::Manager;
use tauri_plugin_fs::FsExt;
pub mod commands; pub mod commands;
pub mod osudb; pub mod osudb;
@@ -30,9 +31,32 @@ pub fn run() {
let mut builder = tauri::Builder::default(); let mut builder = tauri::Builder::default();
#[cfg(desktop)] #[cfg(desktop)]
{ {
builder = builder.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| { builder = builder.plugin(tauri_plugin_single_instance::init(|app, args, _cwd| {
let app_window = app.get_webview_window("main").expect("no main window"); let app_window = app.get_webview_window("main").expect("no main window");
app_window.set_focus().expect("failed to focus"); app_window.set_focus().expect("failed to focus");
if args.len() > 1 {
use tauri::Emitter;
let mut files = Vec::new();
for maybe_file in args.iter().skip(1) {
if maybe_file.starts_with("-") {
continue;
}
let path = PathBuf::from(maybe_file);
if path.extension().and_then(|e| e.to_str()) == Some("ezpplauncher-theme") {
app.fs_scope().allow_file(&path).ok();
files.push(path);
}
}
app.state::<OpenedUrls>().0.lock().unwrap().extend(files.clone());
app.emit("opened", files.clone()).ok();
}
})); }));
} }
@@ -48,21 +72,12 @@ pub fn run() {
continue; continue;
} }
if let Ok(url) = url::Url::parse(&maybe_file) { let path = PathBuf::from(maybe_file);
if let Ok(path) = url.to_file_path() { if path.extension().and_then(|e| e.to_str()) == Some("ezpplauncher-theme") {
if path.extension().and_then(|str| str.to_str()) app.fs_scope().allow_file(&path).ok();
== Some("ezpplauncher-theme")
{
files.push(path); files.push(path);
} }
} }
} else {
let maybe_file_path = PathBuf::from(maybe_file);
if maybe_file_path.extension().and_then(|str| str.to_str()) == Some("ezpplauncher-theme") {
files.push(maybe_file_path);
}
}
}
app.state::<OpenedUrls>().0.lock().unwrap().extend(files); app.state::<OpenedUrls>().0.lock().unwrap().extend(files);
} }
+38 -20
View File
@@ -286,8 +286,13 @@ export const downloadTheme = async (
const downloadableThemes = await getDownloadableThemes(); const downloadableThemes = await getDownloadableThemes();
custom_themes.update((themes) => { custom_themes.update((themes) => {
const reloadedThemes = [...themes]; const reloadedThemes = [...themes];
for (const theme of downloadableThemes) { for (const theme of downloadableThemes) {
if (!reloadedThemes.find((t) => t.name === theme.name)) reloadedThemes.push(theme); if (theme.name === 'Default') continue; // never overwrite Default from remote
if (!reloadedThemes.find((t) => t.name === theme.name)) {
reloadedThemes.push(theme);
}
const installedTheme = reloadedThemes.find((t) => t.name === theme.name); const installedTheme = reloadedThemes.find((t) => t.name === theme.name);
if (installedTheme) { if (installedTheme) {
@@ -300,17 +305,21 @@ export const downloadTheme = async (
} }
} }
} }
for (const installedThemes of reloadedThemes) {
if (installedThemes.name === theme.name) { for (const installedTheme of reloadedThemes) {
installedThemes.name = themeInfoObj.name; if (installedTheme.name === 'Default') continue; // never touch Default
installedThemes.author = themeInfoObj.author;
installedThemes.version = themeInfoObj.version; if (installedTheme.name === theme.name) {
installedThemes.scriptUrl = themeScriptUrl; installedTheme.name = themeInfoObj.name;
installedThemes.assets = themeAssets; installedTheme.author = themeInfoObj.author;
installedThemes.preview = themePreview; installedTheme.version = themeInfoObj.version;
installedThemes.status = 'installed'; installedTheme.scriptUrl = themeScriptUrl;
installedTheme.assets = themeAssets;
installedTheme.preview = themePreview;
installedTheme.status = 'installed';
} }
} }
return reloadedThemes.sort((a, b) => { return reloadedThemes.sort((a, b) => {
if (a.name === 'Default') return -1; if (a.name === 'Default') return -1;
if (b.name === 'Default') return 1; if (b.name === 'Default') return 1;
@@ -469,8 +478,13 @@ export const importThemeFromFile = async (themeName: string, filePath: string) =
const downloadableThemes = await getDownloadableThemes(); const downloadableThemes = await getDownloadableThemes();
custom_themes.update((themes) => { custom_themes.update((themes) => {
const reloadedThemes = [...themes]; const reloadedThemes = [...themes];
for (const theme of downloadableThemes) { for (const theme of downloadableThemes) {
if (!reloadedThemes.find((t) => t.name === theme.name)) reloadedThemes.push(theme); if (theme.name === 'Default') continue; // never overwrite Default from remote
if (!reloadedThemes.find((t) => t.name === theme.name)) {
reloadedThemes.push(theme);
}
const installedTheme = reloadedThemes.find((t) => t.name === theme.name); const installedTheme = reloadedThemes.find((t) => t.name === theme.name);
if (installedTheme) { if (installedTheme) {
@@ -483,17 +497,21 @@ export const importThemeFromFile = async (themeName: string, filePath: string) =
} }
} }
} }
for (const installedThemes of reloadedThemes) {
if (installedThemes.name === themeName) { for (const installedTheme of reloadedThemes) {
installedThemes.name = themeInfoObj.name; if (installedTheme.name === 'Default') continue; // never touch Default
installedThemes.author = themeInfoObj.author;
installedThemes.version = themeInfoObj.version; if (installedTheme.name === themeName) {
installedThemes.scriptUrl = themeScriptUrl; installedTheme.name = themeInfoObj.name;
installedThemes.assets = themeAssets; installedTheme.author = themeInfoObj.author;
installedThemes.preview = themePreview; installedTheme.version = themeInfoObj.version;
installedThemes.status = 'installed'; installedTheme.scriptUrl = themeScriptUrl;
installedTheme.assets = themeAssets;
installedTheme.preview = themePreview;
installedTheme.status = 'installed';
} }
} }
return reloadedThemes.sort((a, b) => { return reloadedThemes.sort((a, b) => {
if (a.name === 'Default') return -1; if (a.name === 'Default') return -1;
if (b.name === 'Default') return 1; if (b.name === 'Default') return 1;
+1 -1
View File
@@ -808,7 +808,7 @@
await listen<string[]>('opened', async (event) => { await listen<string[]>('opened', async (event) => {
const files = event.payload; const files = event.payload;
if (files.length > 0) { if (files.length > 0) {
const firstFile = initialUrls[0]; const firstFile = files[0];
if (!firstFile.endsWith('.ezpplauncher-theme')) { if (!firstFile.endsWith('.ezpplauncher-theme')) {
sileo.error({ sileo.error({
title: 'Uhh...', title: 'Uhh...',