Add incognito mode.
This commit is contained in:
parent
9b3af305ca
commit
7e4d168429
|
@ -1,2 +1,2 @@
|
||||||
import { PageState } from "./PageState";
|
import { PageState } from "./state/PageState";
|
||||||
export const pageState = new PageState();
|
export const pageState = new PageState();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { PageRouter } from "z-pagerouter";
|
import { PageRouter } from "z-pagerouter";
|
||||||
import { PageState } from "./PageState";
|
import { PageState } from "./state/PageState";
|
||||||
import { getSealStatus } from "./api/sys/getSealStatus";
|
import { getSealStatus } from "./api/sys/getSealStatus";
|
||||||
import { lookupSelf } from "./api/sys/lookupSelf";
|
import { lookupSelf } from "./api/sys/lookupSelf";
|
||||||
import ClipboardJS from "clipboard";
|
import ClipboardJS from "clipboard";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { JSX } from "preact/jsx-runtime";
|
import { JSX } from "preact/jsx-runtime";
|
||||||
import { PageRouter } from "z-pagerouter";
|
import { PageRouter } from "z-pagerouter";
|
||||||
import { PageState } from "../../PageState";
|
import { PageState } from "../../state/PageState";
|
||||||
|
|
||||||
function currentTitleSecretText(state: PageState): string {
|
function currentTitleSecretText(state: PageState): string {
|
||||||
let secretItemText = state.secretItem;
|
let secretItemText = state.secretItem;
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Grid, GridSizes } from "../../../elements/Grid";
|
||||||
import { MarginInline } from "../../../elements/MarginInline";
|
import { MarginInline } from "../../../elements/MarginInline";
|
||||||
import { Page } from "../../../types/Page";
|
import { Page } from "../../../types/Page";
|
||||||
import { PageRouter } from "z-pagerouter";
|
import { PageRouter } from "z-pagerouter";
|
||||||
import { PageState } from "../../../PageState";
|
import { PageState } from "../../../state/PageState";
|
||||||
import { SecretTitleElement } from "../SecretTitleElement";
|
import { SecretTitleElement } from "../SecretTitleElement";
|
||||||
import { getTOTPCode } from "../../../api/totp/getTOTPCode";
|
import { getTOTPCode } from "../../../api/totp/getTOTPCode";
|
||||||
import { getTOTPKeys } from "../../../api/totp/getTOTPKeys";
|
import { getTOTPKeys } from "../../../api/totp/getTOTPKeys";
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { PageRouter } from "z-pagerouter";
|
import { PageRouter } from "z-pagerouter";
|
||||||
import { PageState } from "./PageState";
|
import { PageState } from "./state/PageState";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
|
|
||||||
// Playground is a way to debug and test things.
|
// Playground is a way to debug and test things.
|
||||||
|
|
|
@ -1,9 +1,18 @@
|
||||||
|
import { StorageType } from "./storage/StorageType";
|
||||||
|
|
||||||
export class PageState {
|
export class PageState {
|
||||||
constructor() {
|
constructor() {
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
if (params.has("reset")) localStorage.clear();
|
if (params.has("reset")) this.storage.clear();
|
||||||
|
if (params.has("incognito")) {
|
||||||
|
this.storage = sessionStorage;
|
||||||
|
} else {
|
||||||
|
this.storage = localStorage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private storage: StorageType;
|
||||||
|
|
||||||
// NOTE: When a item in the page state isn't a string (e.g it is a array or object),
|
// NOTE: When a item in the page state isn't a string (e.g it is a array or object),
|
||||||
// you need to add helper methods to mutate it or else it wont save.
|
// you need to add helper methods to mutate it or else it wont save.
|
||||||
// example: secretPath is a array so when you try to .push() to it
|
// example: secretPath is a array so when you try to .push() to it
|
||||||
|
@ -14,40 +23,40 @@ export class PageState {
|
||||||
// the clunkyness of this approach, but for now, this works.
|
// the clunkyness of this approach, but for now, this works.
|
||||||
|
|
||||||
get apiURL(): string | null {
|
get apiURL(): string | null {
|
||||||
const apiurl = localStorage.getItem("apiURL") || "";
|
const apiurl = this.storage.getItem("apiURL") || "";
|
||||||
return apiurl.length > 0 ? apiurl : null;
|
return apiurl.length > 0 ? apiurl : null;
|
||||||
}
|
}
|
||||||
set apiURL(value: string) {
|
set apiURL(value: string) {
|
||||||
localStorage.setItem("apiURL", value);
|
this.storage.setItem("apiURL", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get token(): string | null {
|
get token(): string | null {
|
||||||
const tok = localStorage.getItem("token") || "";
|
const tok = this.storage.getItem("token") || "";
|
||||||
return tok.length > 0 ? tok : null;
|
return tok.length > 0 ? tok : null;
|
||||||
}
|
}
|
||||||
set token(value: string) {
|
set token(value: string) {
|
||||||
localStorage.setItem("token", value);
|
this.storage.setItem("token", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get pageDirection(): string {
|
get pageDirection(): string {
|
||||||
return localStorage.getItem("pageDirection") || "ltr";
|
return this.storage.getItem("pageDirection") || "ltr";
|
||||||
}
|
}
|
||||||
set pageDirection(value: string) {
|
set pageDirection(value: string) {
|
||||||
localStorage.setItem("pageDirection", value);
|
this.storage.setItem("pageDirection", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get language(): string {
|
get language(): string {
|
||||||
return localStorage.getItem("language") || "";
|
return this.storage.getItem("language") || "";
|
||||||
}
|
}
|
||||||
set language(value: string) {
|
set language(value: string) {
|
||||||
localStorage.setItem("language", value);
|
this.storage.setItem("language", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get baseMount(): string {
|
get baseMount(): string {
|
||||||
return localStorage.getItem("baseMount") || "";
|
return this.storage.getItem("baseMount") || "";
|
||||||
}
|
}
|
||||||
set baseMount(value: string) {
|
set baseMount(value: string) {
|
||||||
localStorage.setItem("baseMount", value);
|
this.storage.setItem("baseMount", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since this is a array we can't act directly on it so we need
|
// Since this is a array we can't act directly on it so we need
|
||||||
|
@ -65,60 +74,60 @@ export class PageState {
|
||||||
}
|
}
|
||||||
|
|
||||||
get secretPath(): string[] {
|
get secretPath(): string[] {
|
||||||
return JSON.parse(localStorage.getItem("secretPath") || "[]") as string[];
|
return JSON.parse(this.storage.getItem("secretPath") || "[]") as string[];
|
||||||
}
|
}
|
||||||
set secretPath(value: string[]) {
|
set secretPath(value: string[]) {
|
||||||
localStorage.setItem("secretPath", JSON.stringify(value));
|
this.storage.setItem("secretPath", JSON.stringify(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
get secretVersion(): string | null {
|
get secretVersion(): string | null {
|
||||||
const result = localStorage.getItem("secretVersion");
|
const result = this.storage.getItem("secretVersion");
|
||||||
return result != "null" ? result || null : null;
|
return result != "null" ? result || null : null;
|
||||||
}
|
}
|
||||||
set secretVersion(value: string) {
|
set secretVersion(value: string) {
|
||||||
localStorage.setItem("secretVersion", String(value));
|
this.storage.setItem("secretVersion", String(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
get secretItem(): string {
|
get secretItem(): string {
|
||||||
return localStorage.getItem("secretItem") || "";
|
return this.storage.getItem("secretItem") || "";
|
||||||
}
|
}
|
||||||
set secretItem(value: string) {
|
set secretItem(value: string) {
|
||||||
localStorage.setItem("secretItem", value);
|
this.storage.setItem("secretItem", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get secretMountType(): string {
|
get secretMountType(): string {
|
||||||
return localStorage.getItem("secretMountType") || "";
|
return this.storage.getItem("secretMountType") || "";
|
||||||
}
|
}
|
||||||
set secretMountType(value: string) {
|
set secretMountType(value: string) {
|
||||||
localStorage.setItem("secretMountType", value);
|
this.storage.setItem("secretMountType", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get policyItem(): string {
|
get policyItem(): string {
|
||||||
return localStorage.getItem("policyItem") || "";
|
return this.storage.getItem("policyItem") || "";
|
||||||
}
|
}
|
||||||
set policyItem(value: string) {
|
set policyItem(value: string) {
|
||||||
localStorage.setItem("policyItem", value);
|
this.storage.setItem("policyItem", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get authPath(): string {
|
get authPath(): string {
|
||||||
return localStorage.getItem("authPath") || "";
|
return this.storage.getItem("authPath") || "";
|
||||||
}
|
}
|
||||||
set authPath(value: string) {
|
set authPath(value: string) {
|
||||||
localStorage.setItem("authPath", value);
|
this.storage.setItem("authPath", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get userPassUser(): string {
|
get userPassUser(): string {
|
||||||
return localStorage.getItem("userPassUser") || "";
|
return this.storage.getItem("userPassUser") || "";
|
||||||
}
|
}
|
||||||
set userPassUser(value: string) {
|
set userPassUser(value: string) {
|
||||||
localStorage.setItem("userPassUser", value);
|
this.storage.setItem("userPassUser", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get currentPage(): string {
|
get currentPage(): string {
|
||||||
const curPage = localStorage.getItem("currentPage") || "HOME";
|
const curPage = this.storage.getItem("currentPage") || "HOME";
|
||||||
return curPage;
|
return curPage;
|
||||||
}
|
}
|
||||||
set currentPage(value: string) {
|
set currentPage(value: string) {
|
||||||
localStorage.setItem("currentPage", value);
|
this.storage.setItem("currentPage", value);
|
||||||
}
|
}
|
||||||
}
|
}
|
5
src/state/storage/StorageType.ts
Normal file
5
src/state/storage/StorageType.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
export interface StorageType {
|
||||||
|
clear(): void;
|
||||||
|
getItem(key: string): string;
|
||||||
|
setItem(key: string, value: string);
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
import { PageRouter } from "z-pagerouter";
|
import { PageRouter } from "z-pagerouter";
|
||||||
import { PageState } from "../PageState";
|
import { PageState } from "../state/PageState";
|
||||||
|
|
||||||
export class Page {
|
export class Page {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
Loading…
Reference in a new issue