Compare commits

...
Author SHA1 Message Date
Calum H. (IMB11) fa7209687a fix: file picker in app 2026-05-07 15:47:02 +01:00
@@ -1,6 +1,17 @@
import { provideFilePicker } from '@modrinth/ui'
import { convertFileSrc } from '@tauri-apps/api/core'
import { open } from '@tauri-apps/plugin-dialog'
import { readFile } from '@tauri-apps/plugin-fs'
function getFileName(path: string, fallback: string) {
return path.split(/[\\/]/).pop() || fallback
}
async function createFileFromPath(path: string, fallbackName: string, type?: string) {
const bytes = await readFile(path)
const name = getFileName(path, fallbackName)
return new File([bytes], name, type ? { type } : undefined)
}
export function setupFilePickerProvider() {
provideFilePicker({
@@ -12,8 +23,7 @@ export function setupFilePickerProvider() {
if (!result) return null
const path = result.path ?? result
if (!path) return null
const name = path.split(/[\\/]/).pop() || 'icon'
const file = new File([], name)
const file = await createFileFromPath(path, 'icon')
return { file, path, previewUrl: convertFileSrc(path) }
},
async pickModpackFile() {
@@ -24,8 +34,11 @@ export function setupFilePickerProvider() {
if (!result) return null
const path = result.path ?? result
if (!path) return null
const name = path.split(/[\\/]/).pop() || 'modpack.mrpack'
const file = new File([], name)
const file = await createFileFromPath(
path,
'modpack.mrpack',
'application/x-modrinth-modpack+zip',
)
return { file, path, previewUrl: '' }
},
})