fix: cluster icons displays the right image

This commit is contained in:
emirsassan 2025-07-09 14:06:37 +03:00
parent 03259473a3
commit 541b148984
3 changed files with 31 additions and 15 deletions

View file

@ -75,6 +75,12 @@ async fn initialize_tauri(builder: tauri::Builder<tauri::Wry>) -> LauncherResult
.menu(tauri::menu::Menu::new)
.invoke_handler(router.into_handler())
.setup(move |app| {
let launcher_path = app.path().data_dir().ok().expect("ok").join("OneLauncher");
app.asset_protocol_scope()
.allow_directory(&launcher_path, true)
.unwrap();
setup_window(app.handle()).expect("failed to setup main window");
Ok(())
});

View file

@ -37,10 +37,12 @@ function RouteComponent() {
subscribed: false,
});
function handleEditMode() {
if (edit)
editing.refetch();
cluster.refetch();
async function handleEditMode() {
if (edit) {
await editing.refetch();
await cluster.refetch();
}
setEdit(!edit);
}
@ -127,10 +129,11 @@ interface BannerProps {
function Banner({
cluster,
editMode,
newCover,
setNewName,
setNewCover,
}: BannerProps) {
const { set, list } = useNotifications();
const { set } = useNotifications();
async function launchFilePicker() {
const selected = await open({
@ -156,17 +159,11 @@ function Banner({
const handleLaunch = () => {
launch.refetch();
// eslint-disable-next-line no-console -- debug
console.log(list);
if (launch.isError)
set('launch_cluster', {
title: 'Failed to launch cluster',
message: launch.error.message,
});
// eslint-disable-next-line no-console -- debug
console.log(list);
};
function updateName(name: string) {
@ -177,11 +174,23 @@ function Banner({
}
const image = () => {
if (editMode && newCover && newCover !== cluster?.icon_url)
if (newCover.includes('\\') || newCover.includes('/')) {
console.warn('Using preview image:', newCover);
return convertFileSrc(newCover);
}
const url = cluster?.icon_url;
if (!url)
return DefaultInstancePhoto;
// eslint-disable-next-line no-console -- ok
console.log(url);
if (!url) {
console.warn('No icon URL, using default');
return DefaultInstancePhoto;
}
console.warn('Using cached icon:', url);
return convertFileSrc(url);
};
@ -201,7 +210,8 @@ function Banner({
<img
className="h-full w-full"
onError={(e) => {
(e.target as HTMLImageElement).src = DefaultInstancePhoto;
console.error('Failed to load cluster icon:', image(), e);
// (e.target as HTMLImageElement).src = DefaultInstancePhoto;
}}
src={image()}
/>

View file

@ -24,7 +24,7 @@ impl Icon {
return None;
}
Some(Self(format!("file://{}", path.display())))
Some(Self(format!("{}", path.display())))
}
pub fn try_from_url(url: url::Url) -> Option<Self> {