Skip to content

Commit

Permalink
getting it to compile (but its broken)
Browse files Browse the repository at this point in the history
  • Loading branch information
RedstoneWizard08 committed Jul 5, 2024
1 parent 111558d commit b5f1549
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 105 deletions.
22 changes: 9 additions & 13 deletions src/api/bindings/app.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// This file was generated by [rspc](https://github.com/oscartbeaumont/rspc). Do not edit this file manually.

export type Procedures = {
queries:
{ key: "mods", input: number, result: Mod[] } |
{ key: "version", input: never, result: string },
mutations: never,
subscriptions: never
};

export type Mod = { id: number; mod: string; version: string | null; name: string; file: string; size: number; hash: string | null; installed_files: string; sourceId: number; instanceId: number }

export type String = string
export type DbMod = any;
export type Instance = any;
export type ModLoader = any;
export type ModLoaderType = any;
export type Mod = any;
export type Source = any;
export type SourceMapping = any;
export type ModVersion = any;
export type PluginInfo = any;
5 changes: 2 additions & 3 deletions src/api/boot.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { get } from "svelte/store";
import { commands } from "./bindings/app";
import { plugins } from "./stores";
import { unwrap } from "./util";
// import { unwrap } from "./util";

export const boot = async () => {
console.log("Backend booting...");

plugins.set(unwrap(await commands.getPlugins(null)).sort((a, b) => a.game - b.game));
// plugins.set(unwrap(await commands.getPlugins(null)).sort((a, b) => a.game - b.game));

console.log(get(plugins));
};
2 changes: 1 addition & 1 deletion src/api/loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ModLoader } from "./bindings/app";
type ModLoader = string;

export const getLoader = (loader: ModLoader): string => {
return Object.keys(loader)[0];
Expand Down
3 changes: 2 additions & 1 deletion src/api/stores.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { writable } from "svelte/store";
import type { PluginInfo } from "./bindings/app";

type PluginInfo = any;

export const plugins = writable<PluginInfo[]>([]);
8 changes: 3 additions & 5 deletions src/api/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import {
type EventCallback,
type UnlistenFn,
} from "@tauri-apps/api/event";
import type { __Result__ } from "./bindings/app";
import { globalEventBus } from "./dev";

export type __Result__<T, E> = T | E;

export const formatBytes = (n: number) => {
const k = n > 0 ? Math.floor(Math.log2(n) / 10) : 0;
const rank = `${k > 0 ? "KMGTPE"[k - 1] : ""}b`;
Expand All @@ -15,10 +16,7 @@ export const formatBytes = (n: number) => {
};

export const unwrap = <T, E>(res: __Result__<T, E>): T => {
if (res.status === "ok") {
return res.data;
}
throw res.error;
return res as T;
};

export const listen = async <T>(
Expand Down
4 changes: 2 additions & 2 deletions src/components/InstanceCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { goto } from "$app/navigation";
import Delete from "./Delete.svelte";
import { plugins } from "$api/stores";
import { commands, type Instance } from "$bindings";
import type { Instance } from "$bindings";
import { unwrap } from "$api/util";
export let data: Instance;
Expand All @@ -17,7 +17,7 @@ const clicked = () => {
const doLaunch = async (e: MouseEvent) => {
e.stopPropagation();
unwrap(await commands.launchGame(data.game_id, data, null));
// unwrap(await commands.launchGame(data.game_id, data, null));
};
const doDelete = async (e: MouseEvent) => {
Expand Down
16 changes: 8 additions & 8 deletions src/components/LoaderDropdown.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { commands, type ModLoader, type ModLoaderType } from "$api/bindings/app";
import type { ModLoader, ModLoaderType } from "$api/bindings/app";
import { getLoader, getLoaderVersion, getMinecraft } from "$api/loader";
import { isRelease, isSnapshot } from "$api/mc";
import { isChildOf, unwrap } from "$api/util";
Expand Down Expand Up @@ -51,10 +51,10 @@ onMount(async () => {
if (loader) {
vanillaVer = getMinecraft(loader);
} else {
vanillaVer = getMinecraft(unwrap(await commands.getLatestLoader("Vanilla", null)));
// vanillaVer = getMinecraft(unwrap(await commands.getLatestLoader("Vanilla", null)));
}
vanilla = unwrap(await commands.getLoaders("Vanilla", null));
// vanilla = unwrap(await commands.getLoaders("Vanilla", null));
window.addEventListener("click", (ev) => {
if (
Expand Down Expand Up @@ -84,19 +84,19 @@ const updater = (type: ModLoaderType) => {
switch (type) {
case "Vanilla":
vanilla = unwrap(await commands.getLoaders("Vanilla", null));
// vanilla = unwrap(await commands.getLoaders("Vanilla", null));
break;
case "Forge":
forge = unwrap(await commands.getLoaders("Forge", null));
// forge = unwrap(await commands.getLoaders("Forge", null));
break;
case "NeoForge":
neoforge = unwrap(await commands.getLoaders("NeoForge", null));
// neoforge = unwrap(await commands.getLoaders("NeoForge", null));
break;
case "Fabric":
fabric = unwrap(await commands.getLoaders("Fabric", null));
// fabric = unwrap(await commands.getLoaders("Fabric", null));
break;
case "Quilt":
quilt = unwrap(await commands.getLoaders("Quilt", null));
// quilt = unwrap(await commands.getLoaders("Quilt", null));
break;
case "None":
loader = { Vanilla: vanillaVer || "" };
Expand Down
31 changes: 16 additions & 15 deletions src/components/Mod.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { onMount } from "svelte";
import { commands, type SourceMapping, type Mod } from "$bindings";
// biome-ignore lint/style/useImportType: <explanation>
import { type SourceMapping, type Mod } from "$bindings";
import { unwrap } from "$api/util";
export let mod: Mod;
Expand All @@ -22,11 +23,11 @@ const fmt = new Intl.NumberFormat("en-US", {
});
onMount(async () => {
source = unwrap(await commands.getSourceId(mod.source, null)) as SourceMapping;
// source = unwrap(await commands.getSourceId(mod.source, null)) as SourceMapping;
const mods = unwrap(await commands.getMods(instance, null));
// const mods = unwrap(await commands.getMods(instance, null));
installed = mods.find((v) => v.mod_id === mod.id) != null;
// installed = mods.find((v) => v.mod_id === mod.id) != null;
});
const download = async (ev: MouseEvent) => {
Expand All @@ -35,24 +36,24 @@ const download = async (ev: MouseEvent) => {
installing = true;
const resolver = unwrap(await commands.getSourceId(mod.source, null)) as SourceMapping;
const instanceInfo = unwrap(await commands.getInstance(instance, null));
const latest = unwrap(
await commands.getLatestVersion(game, resolver, instanceInfo, mod.id, null)
);
// const resolver = unwrap(await commands.getSourceId(mod.source, null)) as SourceMapping;
// const instanceInfo = unwrap(await commands.getInstance(instance, null));
// const latest = unwrap(
// await commands.getLatestVersion(game, resolver, instanceInfo, mod.id, null)
// );
if (installed) {
const mods = unwrap(await commands.getMods(instance, null));
const me = mods.find((v) => v.mod_id === mod.id);
// const mods = unwrap(await commands.getMods(instance, null));
// const me = mods.find((v) => v.mod_id === mod.id);
unwrap(await commands.uninstallMod(game, me!, instanceInfo, null));
// unwrap(await commands.uninstallMod(game, me!, instanceInfo, null));
} else {
unwrap(await commands.installMod(game, mod, latest, instanceInfo, null));
// unwrap(await commands.installMod(game, mod, latest, instanceInfo, null));
}
const mods = unwrap(await commands.getMods(instance, null));
// const mods = unwrap(await commands.getMods(instance, null));
installed = mods.find((v) => v.mod_id === mod.id) != null;
// installed = mods.find((v) => v.mod_id === mod.id) != null;
installing = false;
};
Expand Down
6 changes: 3 additions & 3 deletions src/components/ModEntry.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script lang="ts">
import { formatBytes, unwrap } from "$api/util";
import { createEventDispatcher, onMount } from "svelte";
import { commands, type DbMod, type Instance } from "$api/bindings/app";
import Delete from "./Delete.svelte";
import type { DbMod, Instance } from "$api/bindings/app";
export let mod: DbMod | null = null;
export let instance: Instance;
Expand All @@ -13,11 +13,11 @@ let source: string | null = null;
const disp = createEventDispatcher();
onMount(async () => {
source = unwrap(await commands.getSourceId(mod?.source_id!, null));
// source = unwrap(await commands.getSourceId(mod?.source_id!, null));
});
const uninstall = async () => {
unwrap(await commands.uninstallMod(instance.game_id, mod!, instance, null));
// unwrap(await commands.uninstallMod(instance.game_id, mod!, instance, null));
disp("uninstall");
};
Expand Down
13 changes: 7 additions & 6 deletions src/routes/[game]/instance/[instance]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { unwrap } from "$api/util";
import Back from "$components/Back.svelte";
import { goto } from "$app/navigation";
import { plugins } from "$api/stores";
import { commands, type DbMod, type Instance, type ModLoader } from "$bindings";
import type { DbMod, Instance, ModLoader } from "$bindings";
import { onMount } from "svelte";
import LoaderDropdown from "$components/LoaderDropdown.svelte";
Expand All @@ -24,8 +24,8 @@ $: description = instance?.description;
const id = $page.params.instance;
const refresh = async () => {
instance = unwrap(await commands.getInstance(Number.parseInt(id || "-1", 10), null));
mods = unwrap(await commands.getMods(instance.id!, null));
// instance = unwrap(await commands.getInstance(Number.parseInt(id || "-1", 10), null));
// mods = unwrap(await commands.getMods(instance.id!, null));
background = $plugins.find((v) => v.game === instance.game_id)?.banner_url;
executable = instance.data_dir;
Expand All @@ -38,7 +38,8 @@ onMount(refresh);
const save = async () => {
if (instance) {
instance = unwrap(
await commands.updateInstance(instance.id!, editor?.value || instance.description, null)
null
// await commands.updateInstance(instance.id!, editor?.value || instance.description, null)
);
}
Expand All @@ -56,7 +57,7 @@ const edit = () => {
const launch = async () => {
if (instance == null) return;
console.log(unwrap(await commands.launchGame(instance.game_id, instance, null)));
// console.log(unwrap(await commands.launchGame(instance.game_id, instance, null)));
};
const updateDescription = (ev: Event) => {
Expand All @@ -73,7 +74,7 @@ const reinstall = async () => {
if (instance == null) return;
installing = true;
instance = unwrap(await commands.installLoader(loader!, instance, null));
// instance = unwrap(await commands.installLoader(loader!, instance, null));
installing = false;
};
</script>
Expand Down
12 changes: 6 additions & 6 deletions src/routes/[game]/instances/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import InstanceCard from "$components/InstanceCard.svelte";
import { onMount } from "svelte";
import { page } from "$app/stores";
import { commands, type Instance } from "$bindings";
import type { Instance } from "$bindings";
import { unwrap } from "$api/util";
let adding = false;
Expand All @@ -15,24 +15,24 @@ let gameId = Number.parseInt($page.params.game);
let name = "";
onMount(async () => {
instances = unwrap(await commands.getInstances(gameId, null));
// instances = unwrap(await commands.getInstances(gameId, null));
});
const addInstance = async () => {
unwrap(await commands.createInstance(name, gameId, null));
// unwrap(await commands.createInstance(name, gameId, null));
name = "";
adding = false;
instances = unwrap(await commands.getInstances(gameId, null));
// instances = unwrap(await commands.getInstances(gameId, null));
};
const deleteInstance = async () => {
commands.deleteInstance(current?.id!, null);
// commands.deleteInstance(current?.id!, null);
deleteing = false;
instances = unwrap(await commands.getInstances(gameId, null));
// instances = unwrap(await commands.getInstances(gameId, null));
};
const toggleAdding = () => {
Expand Down
42 changes: 21 additions & 21 deletions src/routes/[game]/mod/[source]/[mod]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import DOMPurify from "dompurify";
import { page } from "$app/stores";
import LoadingPage from "$components/LoadingPage.svelte";
import { listen, unwrap } from "$api/util";
import { commands, type SourceMapping, type Mod, type ModVersion } from "$bindings";
import type { SourceMapping, Mod, ModVersion } from "$bindings";
import { marked } from "marked";
import { onMount } from "svelte";
import Dropdown from "$components/Dropdown.svelte";
Expand Down Expand Up @@ -35,16 +35,16 @@ const fmt = new Intl.NumberFormat("en-US", {
onMount(async () => {
if (modId || $page.url) {
const instance = unwrap(await commands.getInstance(instanceId, null));
// const instance = unwrap(await commands.getInstance(instanceId, null));
mods = /\/mods?(\/\d+)?/i.test($page.url.pathname);
modInfo = unwrap(await commands.getMod(gameId, source as SourceMapping, modId, null));
versions = unwrap(
await commands.getModVersions(gameId, source as SourceMapping, instance, modId, null)
);
latest = unwrap(
await commands.getLatestVersion(gameId, source as SourceMapping, instance, modId, null)
);
// modInfo = unwrap(await commands.getMod(gameId, source as SourceMapping, modId, null));
// versions = unwrap(
// await commands.getModVersions(gameId, source as SourceMapping, instance, modId, null)
// );
// latest = unwrap(
// await commands.getLatestVersion(gameId, source as SourceMapping, instance, modId, null)
// );
isLoading = false;
selected = { id: latest.id, text: latest.name! };
Expand All @@ -53,9 +53,9 @@ onMount(async () => {
? modInfo.icon?.replace("https://cdn.modrinth.com/", "/__mr_cdn/")
: modInfo.icon;
const modsList = unwrap(await commands.getMods(instanceId, null));
// const modsList = unwrap(await commands.getMods(instanceId, null));
installed = modsList.find((v) => v.mod_id === modId) != null;
// installed = modsList.find((v) => v.mod_id === modId) != null;
}
listen("progress_callback", (data) => {
Expand Down Expand Up @@ -121,29 +121,29 @@ const install = async () => {
downloading = true;
const version = versions.find((v) => v.id === selected.id)!;
const instance = unwrap(await commands.getInstance(instanceId, null));
// const instance = unwrap(await commands.getInstance(instanceId, null));
unwrap(await commands.installMod(gameId, modInfo!, version, instance, null));
// unwrap(await commands.installMod(gameId, modInfo!, version, instance, null));
const mods = unwrap(await commands.getMods(instance.id!, null));
// const mods = unwrap(await commands.getMods(instance.id!, null));
installed = mods.find((v) => v.mod_id === modId) != null;
// installed = mods.find((v) => v.mod_id === modId) != null;
downloading = false;
};
const uninstall = async () => {
downloading = true;
const instance = unwrap(await commands.getInstance(instanceId, null));
const modsNow = unwrap(await commands.getMods(instance.id!, null));
const me = modsNow.find((v) => v.mod_id === modId)!;
// const instance = unwrap(await commands.getInstance(instanceId, null));
// const modsNow = unwrap(await commands.getMods(instance.id!, null));
// const me = modsNow.find((v) => v.mod_id === modId)!;
unwrap(await commands.uninstallMod(gameId, me, instance, null));
// unwrap(await commands.uninstallMod(gameId, me, instance, null));
const mods = unwrap(await commands.getMods(instance.id!, null));
// const mods = unwrap(await commands.getMods(instance.id!, null));
installed = mods.find((v) => v.mod_id === modId) != null;
// installed = mods.find((v) => v.mod_id === modId) != null;
downloading = false;
};
Expand Down
Loading

0 comments on commit b5f1549

Please sign in to comment.