Skip to content

Commit

Permalink
feat: switched to all custom dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tormak9970 committed Aug 19, 2023
1 parent 60e9fcd commit a783ee4
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 120 deletions.
1 change: 1 addition & 0 deletions src/Stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const updateManifest: Writable<UpdateManifest> = writable(null);
export const showDialogModal = writable(false);
export const dialogModalTitle = writable("");
export const dialogModalMessage = writable("");
export const dialogModalType: Writable<DialogModalType> = writable('INFO');
export const dialogModalConfirmText = writable("");
export const dialogModalConfirm = writable(async () => {});
export const dialogModalCancelText = writable("");
Expand Down
7 changes: 2 additions & 5 deletions src/components/Footer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
import Button from "./interactables/Button.svelte";
import IconButton from "./interactables/IconButton.svelte";
import HorizontalSpacer from "./spacers/HorizontalSpacer.svelte";
import { dialog } from "@tauri-apps/api";
import { DialogController } from "../lib/controllers/DialogController";
async function onCleanGridsClick(): Promise<void> {
if ($canSave) {
const shouldSaveAndOpen = await dialog.ask("You need to save your changes before cleaning. Would you like to save?", {
title: "Found existing changes",
type: "warning"
});
const shouldSaveAndOpen = await DialogController.ask("Found in Progress Changes", "WARNING", "You need to save your changes before cleaning. Would you like to save?", "Yes", "No");
if (shouldSaveAndOpen) {
await AppController.saveChanges();
Expand Down
12 changes: 6 additions & 6 deletions src/components/Titlebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { onMount } from "svelte";
import { exit } from "@tauri-apps/api/process";
import { canSave } from "../Stores";
import { dialog } from "@tauri-apps/api";
import { LogController } from "../lib/controllers/LogController";
import { DialogController } from "../lib/controllers/DialogController";
export let title: string;
Expand All @@ -24,11 +24,11 @@
console.log(title);
if (title == "Steam Art Manager") {
if ($canSave) {
const shouldQuit = await dialog.confirm("You have unsaved changes! Quitting will cause you to loose them", {
title: "Unsaved Changes!",
type: "warning"
});
if (shouldQuit) await exit(0);
const shouldQuit = await DialogController.ask("Unsaved Changes!", "WARNING", "You have unsaved changes! Quitting will cause you to loose them", "Confirm", "Cancel");
if (shouldQuit) {
const success = await exit(0);
LogController.log(`Program exited: ${success}`);
}
} else {
const success = await exit(0);
LogController.log(`Program exited: ${success}`);
Expand Down
32 changes: 30 additions & 2 deletions src/components/modals/DialogModal.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { dialogModalCancel, dialogModalCancelText, dialogModalConfirm, dialogModalConfirmText, dialogModalMessage, dialogModalTitle, showDialogModal } from "../../Stores";
import { dialogModalCancel, dialogModalCancelText, dialogModalConfirm, dialogModalConfirmText, dialogModalMessage, dialogModalTitle, dialogModalType, showDialogModal } from "../../Stores";
import Button from "../interactables/Button.svelte";
import ModalBody from "./modal-utils/ModalBody.svelte";
Expand All @@ -17,6 +17,7 @@
$showDialogModal = false;
setTimeout(() => {
$dialogModalTitle = "";
$dialogModalType = "INFO";
$dialogModalMessage = "";
$dialogModalConfirmText = "";
$dialogModalConfirm = async () => {};
Expand All @@ -29,7 +30,27 @@
<!-- svelte-ignore a11y-click-events-have-key-events -->
<ModalBody title={$dialogModalTitle} canClose={false}>
<div class="content">
<div class="info">{$dialogModalMessage}</div>
<div class="info">
<div class="type-cont">
{#if $dialogModalType === "INFO"}
<svg xmlns="http://www.w3.org/2000/svg" height="3em" viewBox="0 0 512 512" fill="#04a3ff">
<!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. -->
<path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/>
</svg>
{:else if $dialogModalType === "WARNING"}
<svg xmlns="http://www.w3.org/2000/svg" height="3em" viewBox="0 0 512 512" fill="#ffee04">
<!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. -->
<path d="M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7 .2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8 .2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24V296c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224a32 32 0 1 0 -64 0 32 32 0 1 0 64 0z"/>
</svg>
{:else}
<svg xmlns="http://www.w3.org/2000/svg" height="3em" viewBox="0 0 512 512" fill="#e24a4a">
<!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2023 Fonticons, Inc. -->
<path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zm0-384c13.3 0 24 10.7 24 24V264c0 13.3-10.7 24-24 24s-24-10.7-24-24V152c0-13.3 10.7-24 24-24zM224 352a32 32 0 1 1 64 0 32 32 0 1 1 -64 0z"/>
</svg>
{/if}
</div>
<div class="message">{$dialogModalMessage}</div>
</div>
<div class="buttons">
{#if $dialogModalConfirmText !== ""}
<Button label={$dialogModalConfirmText} onClick={onConfirm} width={$dialogModalCancelText !== "" ? "47.5%" : "100%"} />
Expand All @@ -50,6 +71,13 @@
margin: 0px 10px;
margin-top: 7px;
font-size: 14px;
display: flex;
align-items: center;
}
.message {
margin-left: 15px;
}
.buttons {
Expand Down
108 changes: 43 additions & 65 deletions src/lib/controllers/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ToastController } from "./ToastController";
import { SettingsManager } from "../utils/SettingsManager";
import { LogController } from "./LogController";
import { get } from "svelte/store";
import { GridTypes, Platforms, activeUserId, appLibraryCache, canSave, cleanConflicts, currentPlatform, customGameNames, dialogModalCancel, dialogModalCancelText, dialogModalConfirm, dialogModalConfirmText, dialogModalMessage, dialogModalTitle, gridModalInfo, gridType, hiddenGameIds, isOnline, loadingGames, manualSteamGames, needsSGDBAPIKey, needsSteamKey, nonSteamGames, originalAppLibraryCache, originalLogoPositions, originalSteamShortcuts, requestTimeoutLength, selectedGameAppId, selectedGameName, showCleanConflictDialog, showDialogModal, showGridModal, showSettingsModal, steamGames, steamGridDBKey, steamInstallPath, steamKey, steamLogoPositions, steamShortcuts, steamUsers, theme, unfilteredLibraryCache } from "../../Stores";
import { GridTypes, Platforms, activeUserId, appLibraryCache, canSave, cleanConflicts, currentPlatform, customGameNames, gridModalInfo, gridType, hiddenGameIds, isOnline, loadingGames, manualSteamGames, needsSGDBAPIKey, needsSteamKey, nonSteamGames, originalAppLibraryCache, originalLogoPositions, originalSteamShortcuts, requestTimeoutLength, selectedGameAppId, selectedGameName, showCleanConflictDialog, showDialogModal, showGridModal, showSettingsModal, steamGames, steamGridDBKey, steamInstallPath, steamKey, steamLogoPositions, steamShortcuts, steamUsers, theme, unfilteredLibraryCache } from "../../Stores";
import { CacheController } from "./CacheController";
import { RustInterop } from "./RustInterop";
import type { SGDBImage } from "../models/SGDB";
Expand All @@ -30,6 +30,7 @@ import { createTippy } from 'svelte-tippy';
import "tippy.js/dist/tippy.css"
import { hideAll, type Instance, type Props } from "tippy.js";
import { exit } from "@tauri-apps/api/process";
import { DialogController } from "./DialogController";

const gridTypeLUT = {
"capsule": GridTypes.CAPSULE,
Expand Down Expand Up @@ -76,41 +77,44 @@ function getIdFromGridName(gridName: string): [string, string] {
}

async function findSteamPath(savedInstallPath: string): Promise<void> {
if (savedInstallPath !== "") {
if (await fs.exists(savedInstallPath)) {
const steamInstallPathAdded = await RustInterop.addPathToScope(savedInstallPath);

if (steamInstallPathAdded) {
steamInstallPath.set(savedInstallPath);
} else {
// TODO: figure out what to do here. path exists but failed to add it to scope
}
} else {
// * show modal and proceed accordingly
}
} else {
const returnedInstallPath = await RustInterop.addSteamToScope();

if (returnedInstallPath === "") {
// TODO: figure out what to do here. path exists but failed to add it to scope
} else if (returnedInstallPath === "DNE") {
// let hit_ok = MessageDialogBuilder::new("SARM Initialization Error", "Steam was not found on your PC. Steam needs to be installed for SARM to work.")
// .buttons(MessageDialogButtons::Ok)
// .show();

// if hit_ok {
// exit(1);
// }
// TODO: prompt user saying steam was not found, and ask if steam is installed. if yes, show custom field, otherwise, ask to install then exit app.
} else {
steamInstallPath.set(returnedInstallPath);
await SettingsManager.updateSetting("steamInstallPath", returnedInstallPath);
}
}
const returnedInstallPath = await RustInterop.addSteamToScope();

// ! for some reason this is really slow. maybe the fs.exists? May also be that my wifi is shit
// if (savedInstallPath !== "") {
// if (await fs.exists(savedInstallPath)) {
// const steamInstallPathAdded = await RustInterop.addPathToScope(savedInstallPath);

// if (steamInstallPathAdded) {
// steamInstallPath.set(savedInstallPath);
// } else {
// // TODO: figure out what to do here. path exists but failed to add it to scope
// }
// } else {
// // * show modal and proceed accordingly
// }
// } else {
// const returnedInstallPath = await RustInterop.addSteamToScope();

// if (returnedInstallPath === "") {
// // TODO: figure out what to do here. path exists but failed to add it to scope
// } else if (returnedInstallPath === "DNE") {
// // let hit_ok = MessageDialogBuilder::new("SARM Initialization Error", "Steam was not found on your PC. Steam needs to be installed for SARM to work.")
// // .buttons(MessageDialogButtons::Ok)
// // .show();

// // if hit_ok {
// // exit(1);
// // }
// // TODO: prompt user saying steam was not found, and ask if steam is installed. if yes, show custom field, otherwise, ask to install then exit app.
// } else {
// steamInstallPath.set(returnedInstallPath);
// await SettingsManager.updateSetting("steamInstallPath", returnedInstallPath);
// }
// }
}

/**
* The main controller for the application
* The main controller for the application.
*/
export class AppController {
private static cacheController = null;
Expand All @@ -132,26 +136,6 @@ export class AppController {
AppController.tippyInstance = instance;
}

/**
* Sets up and displays a dialog modal.
* @param title The title of the dialog modal.
* @param message The message of the dialog modal.
* @param confirmText The text displayed for the confirm action.
* @param confirmCallback The callback to run on confirm.
* @param cancelText The text displayed for the cancel action.
* @param cancelCallback The callback to run on cancel.
*/
static showBasicModal(title: string, message: string, confirmText: string, confirmCallback: () => Promise<void>, cancelText: string, cancelCallback: () => Promise<void>) {
dialogModalTitle.set(title);
dialogModalMessage.set(message);
dialogModalConfirmText.set(confirmText);
dialogModalConfirm.set(confirmCallback);
dialogModalCancelText.set(cancelText);
dialogModalCancel.set(cancelCallback);

showDialogModal.set(true);
}

/**
* Sets up the AppController.
* ? Logging complete.
Expand All @@ -168,18 +152,12 @@ export class AppController {
const cleanedUsers: { [id: string]: SteamUser } = {};

if (Object.keys(users).length === 0) {
await new Promise<void>((resolve) => {
AppController.showBasicModal(
"No Steam Users Found",
"No Steam users were found while reading the loginusers file. Typically this is because you have not logged in to Steam yet. Please log in at least once, then restart SARM.",
"Ok",
async () => {
resolve();
},
"",
async () => {}
)
});
await DialogController.message(
"No Steam Users Found",
"ERROR",
"No Steam users were found while reading the loginusers file. Typically this is because you have not logged in to Steam yet. Please log in at least once, then restart SARM.",
"Ok",
);
await exit(0);
}

Expand Down
50 changes: 50 additions & 0 deletions src/lib/controllers/DialogController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { dialogModalCancel, dialogModalCancelText, dialogModalConfirm, dialogModalConfirmText, dialogModalMessage, dialogModalTitle, dialogModalType, showDialogModal } from "../../Stores";

/**
* Controller class for handling dialog modals.
*/
export class DialogController {

/**
* Displays a message with a single button.
* @param title The title of the dialog modal.
* @param type The type of the dialog modal.
* @param message The message to display.
* @param confirmText The text displayed in the button.
*/
static async message(title: string, type: DialogModalType, message: string, confirmText: string): Promise<boolean> {
return new Promise((resolve) => {
dialogModalTitle.set(title);
dialogModalType.set(type);
dialogModalMessage.set(message);
dialogModalConfirmText.set(confirmText);
dialogModalConfirm.set(async () => resolve(true));
dialogModalCancelText.set("");
dialogModalCancel.set(async () => {});

showDialogModal.set(true);
});
}

/**
* Asks the user for input on a decision.
* @param title The title of the dialog modal.
* @param type The type of the dialog modal.
* @param message The message of the dialog modal.
* @param confirmText The text displayed for the confirm action.
* @param cancelText The text displayed for the cancel action.
*/
static async ask(title: string, type: DialogModalType, message: string, confirmText: string, cancelText: string): Promise<boolean> {
return new Promise((resolve) => {
dialogModalTitle.set(title);
dialogModalType.set(type);
dialogModalMessage.set(message);
dialogModalConfirmText.set(confirmText);
dialogModalConfirm.set(async () => resolve(true));
dialogModalCancelText.set(cancelText);
dialogModalCancel.set(async () => resolve(false));

showDialogModal.set(true);
});
}
}
2 changes: 1 addition & 1 deletion src/lib/controllers/LogController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { LogLevel, RustInterop } from "./RustInterop";

/**
* Controller that handles all logging done by the app.
* Controller class that handles all logging done by the app.
* ! Should do no logging here.
*/
export class LogController {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/controllers/ToastController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { toast } from "@zerodevx/svelte-toast";

/**
* A controller for handling toast messages.
* Controller class for handling toast messages.
*/
export class ToastController {
/**
Expand Down
39 changes: 39 additions & 0 deletions src/types/SteamTypes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
type SteamRegistryApp = {
appid: string,
name: string
}

type SteamShortcut = {
AllowDesktopConfig: number
AllowOverlay: number
AppName: string
Devkit: number
DevkitGameID: string,
DevkitOverrideAppID: number
Exe: string,
FlatpakAppID: string,
IsHidden: number,
LastPlayTime: number,
LaunchOptions: string,
OpenVR: number,
ShortcutPath: string,
StartDir: string,
appid: number,
icon: string,
tags: {
[key: number]: string
}
}

type SteamUser = {
id64: string,
id32: string,
AccountName: string,
PersonaName: string,
RememberPassword: string,
WantsOfflineMode: string,
SkipOfflineModeWarning: string,
AllowAutoLogin: string,
MostRecent: string,
Timestamp: string
}
Loading

0 comments on commit a783ee4

Please sign in to comment.