Browse Source

[LS] changed clear to delete

master
Eduard Kuzmenko 3 years ago
parent
commit
e773402cbf
  1. 2
      src/components/sidebarLeft/index.ts
  2. 36
      src/lib/localStorage.ts
  3. 4
      src/lib/sessionStorage.ts

2
src/components/sidebarLeft/index.ts

@ -172,7 +172,7 @@ export class AppSidebarLeft extends SidebarSlider { @@ -172,7 +172,7 @@ export class AppSidebarLeft extends SidebarSlider {
icon: 'char z',
text: 'ChatList.Menu.SwitchTo.Z',
onClick: () => {
sessionStorage.set({kz_version: 'z'}).then(() => {
sessionStorage.set({kz_version: 'Z'}).then(() => {
location.href = 'https://web.telegram.org/z/';
});
},

36
src/lib/localStorage.ts

@ -19,7 +19,7 @@ class LocalStorage<Storage extends Record<string, any>> { @@ -19,7 +19,7 @@ class LocalStorage<Storage extends Record<string, any>> {
private cache: Partial<Storage> = {};
private useStorage = true;
constructor(private preserveKeys: (keyof Storage)[]) {
constructor(/* private preserveKeys: (keyof Storage)[] */) {
if(Modes.test) {
this.prefix = 't_';
}
@ -42,6 +42,8 @@ class LocalStorage<Storage extends Record<string, any>> { @@ -42,6 +42,8 @@ class LocalStorage<Storage extends Record<string, any>> {
} catch(err) {
//console.error(err);
}
} else {
value = undefined;
}
return value;
@ -76,12 +78,16 @@ class LocalStorage<Storage extends Record<string, any>> { @@ -76,12 +78,16 @@ class LocalStorage<Storage extends Record<string, any>> {
delete this.cache[key];
}
if(this.useStorage) {
localStorage.removeItem(this.prefix + key);
}
//if(this.useStorage) {
try {
localStorage.removeItem(this.prefix + key);
} catch(err) {
}
//}
}
public clear(preserveKeys: (keyof Storage)[] = this.preserveKeys) {
/* public clear(preserveKeys: (keyof Storage)[] = this.preserveKeys) {
// if(this.useStorage) {
try {
let obj: Partial<Storage> = {};
@ -103,6 +109,18 @@ class LocalStorage<Storage extends Record<string, any>> { @@ -103,6 +109,18 @@ class LocalStorage<Storage extends Record<string, any>> {
}
// }
} */
public clear() {
const keys: string[] = ['dc', 'server_time_offset', 'xt_instance', 'user_auth'];
for(let i = 1; i <= 5; ++i) {
keys.push(`dc${i}_server_salt`);
keys.push(`dc${i}_auth_key`);
}
for(let key of keys) {
this.delete(key, true);
}
}
public toggleStorage(enabled: boolean) {
@ -138,11 +156,11 @@ export default class LocalStorageController<Storage extends Record<string, any>> @@ -138,11 +156,11 @@ export default class LocalStorageController<Storage extends Record<string, any>>
private storage: LocalStorage<Storage>;
constructor(private preserveKeys: (keyof Storage)[] = []) {
constructor(/* private preserveKeys: (keyof Storage)[] = [] */) {
LocalStorageController.STORAGES.push(this);
if(!isWorker) {
this.storage = new LocalStorage(preserveKeys);
this.storage = new LocalStorage(/* preserveKeys */);
}
}
@ -196,8 +214,8 @@ export default class LocalStorageController<Storage extends Record<string, any>> @@ -196,8 +214,8 @@ export default class LocalStorageController<Storage extends Record<string, any>>
return this.proxy<void>('delete', key, saveLocal);
}
public clear(preserveKeys?: (keyof Storage)[]) {
return this.proxy<void>('clear', preserveKeys);
public clear(/* preserveKeys?: (keyof Storage)[] */) {
return this.proxy<void>('clear'/* , preserveKeys */);
}
public toggleStorage(enabled: boolean) {

4
src/lib/sessionStorage.ts

@ -24,7 +24,7 @@ const sessionStorage = new LocalStorageController<{ @@ -24,7 +24,7 @@ const sessionStorage = new LocalStorageController<{
dc5_server_salt: string,
server_time_offset: number,
xt_instance: AppInstance,
kz_version: 'k' | 'z'
}>(['kz_version']);
kz_version: 'K' | 'Z'
}>(/* ['kz_version'] */);
MOUNT_CLASS_TO.appStorage = sessionStorage;
export default sessionStorage;

Loading…
Cancel
Save