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