mirror of
https://github.com/ivabus/gui
synced 2025-04-23 14:07:14 +03:00
show welcome modal once (#489)
* show welcome modal once * move welcome config to authStore --------- Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
This commit is contained in:
parent
b95dd47075
commit
53633ee60c
6 changed files with 22 additions and 21 deletions
|
@ -36,7 +36,7 @@ async function addEmptySessionFile(): Promise<Session> {
|
|||
device_id: await getDeviceId(),
|
||||
locale
|
||||
};
|
||||
await writeSessionData(data);
|
||||
await writeSessionData(data, true);
|
||||
log.info("new session file created");
|
||||
return data;
|
||||
}
|
||||
|
@ -132,10 +132,11 @@ export async function readSessionData(): Promise<Session> {
|
|||
return sessionMemory;
|
||||
}
|
||||
|
||||
export async function writeSessionData(data: Session) {
|
||||
export async function writeSessionData(data: Session, force?: boolean) {
|
||||
try {
|
||||
const existingData = force ? sessionMemory : await readSessionData();
|
||||
sessionMemory = {
|
||||
...sessionMemory,
|
||||
...existingData,
|
||||
...data
|
||||
};
|
||||
|
||||
|
@ -143,8 +144,8 @@ export async function writeSessionData(data: Session) {
|
|||
|
||||
log.info("creating:", sessionFolder);
|
||||
await mkdirp(sessionFolder);
|
||||
log.info("writing session data:", data); // rm this
|
||||
await fs.writeFileSync(sessionFilePath, JSON.stringify(data), {
|
||||
log.info("writing session data:", sessionMemory); // rm this
|
||||
await fs.writeFileSync(sessionFilePath, JSON.stringify(sessionMemory), {
|
||||
encoding: "utf-8"
|
||||
});
|
||||
} catch (error) {
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
import Button from "@tea/ui/button/button.svelte";
|
||||
import clickOutside from "@tea/ui/lib/clickOutside";
|
||||
|
||||
import { navStore } from "$libs/stores"
|
||||
import { authStore } from "$libs/stores"
|
||||
|
||||
const close = () => {
|
||||
navStore.showWelcome.set(false);
|
||||
authStore.updateSession({ hide_welcome: true });
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ import type { Developer } from "@tea/ui/types";
|
|||
import type { Session } from "$libs/types";
|
||||
import { getSession as electronGetSession, updateSession as electronUpdateSession } from "@native";
|
||||
|
||||
import { navStore } from "$libs/stores";
|
||||
|
||||
export let session: Session | null = null;
|
||||
export const getSession = async (): Promise<Session | null> => {
|
||||
session = await electronGetSession();
|
||||
|
@ -32,14 +34,11 @@ export default function initAuthStore() {
|
|||
let timer: NodeJS.Timer | null;
|
||||
|
||||
async function updateSession(data: Session) {
|
||||
const localSession = {
|
||||
device_id: deviceId,
|
||||
key: data.key,
|
||||
user: data.user
|
||||
};
|
||||
|
||||
await electronUpdateSession(localSession);
|
||||
sessionStore.set(localSession);
|
||||
sessionStore.update((val) => ({
|
||||
...val,
|
||||
...data
|
||||
}));
|
||||
await electronUpdateSession(data);
|
||||
}
|
||||
|
||||
async function pollSession() {
|
||||
|
@ -81,6 +80,7 @@ export default function initAuthStore() {
|
|||
deviceId,
|
||||
deviceIdStore,
|
||||
pollSession,
|
||||
clearSession
|
||||
clearSession,
|
||||
updateSession
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { writable } from "svelte/store";
|
||||
import { goto } from "$app/navigation";
|
||||
import { updateSession } from "@native";
|
||||
|
||||
const log = window.require("electron-log");
|
||||
|
||||
export default function initNavStore() {
|
||||
const historyStore = writable<string[]>(["/"]);
|
||||
const showWelcome = writable<boolean>(false);
|
||||
|
||||
let history = ["/"];
|
||||
|
||||
|
@ -20,7 +20,6 @@ export default function initNavStore() {
|
|||
let isMovingBack = false;
|
||||
|
||||
return {
|
||||
showWelcome,
|
||||
historyStore,
|
||||
prevPath: prevPathStore,
|
||||
nextPath: nextPathStore,
|
||||
|
|
|
@ -57,6 +57,7 @@ export interface Session {
|
|||
key?: string;
|
||||
user?: Developer;
|
||||
locale?: string;
|
||||
hide_welcome?: boolean;
|
||||
}
|
||||
|
||||
export enum SideMenuOptions {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
import { page } from "$app/stores";
|
||||
import { t } from "$libs/translations";
|
||||
import { afterNavigate } from "$app/navigation";
|
||||
import { packagesStore, navStore } from "$libs/stores";
|
||||
import { packagesStore, authStore } from "$libs/stores";
|
||||
import Packages from "$components/packages/packages.svelte";
|
||||
import DiscoverPackages from "$components/discover-packages/discover-packages.svelte";
|
||||
import { PackageStates, SideMenuOptions, type GUIPackage } from "$libs/types";
|
||||
|
@ -17,7 +17,7 @@
|
|||
const log = window.require("electron-log");
|
||||
|
||||
const { packageList } = packagesStore;
|
||||
const { showWelcome } = navStore;
|
||||
const { session } = authStore;
|
||||
|
||||
const url = $page.url;
|
||||
|
||||
|
@ -112,7 +112,7 @@
|
|||
</div>
|
||||
|
||||
<SideMenu bind:activeOption={sideMenuOption} />
|
||||
{#if $showWelcome}
|
||||
{#if !$session.hide_welcome}
|
||||
<WelcomeModal />
|
||||
{/if}
|
||||
|
||||
|
|
Loading…
Reference in a new issue