import icon from '../../assets/icons/softwarecenter.svg' import { App, RepoData } from '../../types' import FlowWindow from '../../structures/FlowWindow' import { sanitize } from '../../utils' import nullIcon from '../../assets/icons/application-default-icon.svg' export default class MusicApp implements App { meta = { name: 'Store', description: 'A simple store app.', pkg: 'flow.store', version: '1.0.0', icon } async open (): Promise { const win = window.wm.createWindow({ title: this.meta.name, icon: this.meta.icon, width: 500, height: 700 }) win.content.style.background = 'var(--base)' const config = await window.config() fetch(config.SERVER_URL + '/apps/list/') .then(async (res) => await res.json()) .then(handle) .catch(e => console.error(e)) function handle (repos: RepoData[]): void { win.content.innerHTML = `
` repos.forEach((repo) => { (win.content.querySelector('.repos') as HTMLElement).innerHTML += `

${sanitize(repo.name)}

${sanitize(repo.id)}

` repo.apps.forEach((app) => { (win.content.querySelector(`div[data-repo-id="${sanitize(repo.id)}"] > .apps`) as HTMLElement).innerHTML += `

${sanitize(app.name)}

${sanitize(app.pkg)} download
` window.fs.exists(`/Applications/${app.url.split('/').at(-1) as string}`, (exists) => { if (exists) { (win.content.querySelector(`div[data-pkg="${sanitize(app.pkg)}"] div > .material-symbols-rounded`) as HTMLElement).innerHTML = 'delete'; (win.content.querySelector(`div[data-pkg="${sanitize(app.pkg)}"] div > .material-symbols-rounded`) as HTMLElement).onclick = () => { window.fs.unlink(`/Applications/${app.url.split('/').at(-1) as string}`, () => { window.location.reload() }) } } else { (win.content.querySelector(`div[data-pkg="${sanitize(app.pkg)}"] div > .material-symbols-rounded`) as HTMLElement).onclick = () => { install(app.url) } } }); (win.content.querySelector(`div[data-pkg="${sanitize(app.pkg)}"] div > .material-symbols-rounded`) as HTMLElement).onclick = () => { install(app.url) } }) }) } function install (url: string): void { fetch(url).then(async (res) => await res.text()) .then((data) => { window.fs.exists('/Applications', (exists) => { if (!exists) window.fs.promises.mkdir('/Applications').catch(console.error) window.fs.promises.writeFile(`/Applications/${url.split('/').at(-1) as string}`, data).then(() => window.location.reload()).catch(console.error) }) }).catch(console.error) } return win } }