[LS] changed clear to delete
This commit is contained in:
parent
95b2354a13
commit
e773402cbf
@ -172,7 +172,7 @@ export class AppSidebarLeft extends SidebarSlider {
|
|||||||
icon: 'char z',
|
icon: 'char z',
|
||||||
text: 'ChatList.Menu.SwitchTo.Z',
|
text: 'ChatList.Menu.SwitchTo.Z',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
sessionStorage.set({kz_version: 'z'}).then(() => {
|
sessionStorage.set({kz_version: 'Z'}).then(() => {
|
||||||
location.href = 'https://web.telegram.org/z/';
|
location.href = 'https://web.telegram.org/z/';
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -19,7 +19,7 @@ class LocalStorage<Storage extends Record<string, any>> {
|
|||||||
private cache: Partial<Storage> = {};
|
private cache: Partial<Storage> = {};
|
||||||
private useStorage = true;
|
private useStorage = true;
|
||||||
|
|
||||||
constructor(private preserveKeys: (keyof Storage)[]) {
|
constructor(/* private preserveKeys: (keyof Storage)[] */) {
|
||||||
if(Modes.test) {
|
if(Modes.test) {
|
||||||
this.prefix = 't_';
|
this.prefix = 't_';
|
||||||
}
|
}
|
||||||
@ -42,6 +42,8 @@ class LocalStorage<Storage extends Record<string, any>> {
|
|||||||
} catch(err) {
|
} catch(err) {
|
||||||
//console.error(err);
|
//console.error(err);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
value = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
@ -76,12 +78,16 @@ class LocalStorage<Storage extends Record<string, any>> {
|
|||||||
delete this.cache[key];
|
delete this.cache[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.useStorage) {
|
//if(this.useStorage) {
|
||||||
localStorage.removeItem(this.prefix + key);
|
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) {
|
// if(this.useStorage) {
|
||||||
try {
|
try {
|
||||||
let obj: Partial<Storage> = {};
|
let obj: Partial<Storage> = {};
|
||||||
@ -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) {
|
public toggleStorage(enabled: boolean) {
|
||||||
@ -138,11 +156,11 @@ export default class LocalStorageController<Storage extends Record<string, any>>
|
|||||||
|
|
||||||
private storage: LocalStorage<Storage>;
|
private storage: LocalStorage<Storage>;
|
||||||
|
|
||||||
constructor(private preserveKeys: (keyof Storage)[] = []) {
|
constructor(/* private preserveKeys: (keyof Storage)[] = [] */) {
|
||||||
LocalStorageController.STORAGES.push(this);
|
LocalStorageController.STORAGES.push(this);
|
||||||
|
|
||||||
if(!isWorker) {
|
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>>
|
|||||||
return this.proxy<void>('delete', key, saveLocal);
|
return this.proxy<void>('delete', key, saveLocal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public clear(preserveKeys?: (keyof Storage)[]) {
|
public clear(/* preserveKeys?: (keyof Storage)[] */) {
|
||||||
return this.proxy<void>('clear', preserveKeys);
|
return this.proxy<void>('clear'/* , preserveKeys */);
|
||||||
}
|
}
|
||||||
|
|
||||||
public toggleStorage(enabled: boolean) {
|
public toggleStorage(enabled: boolean) {
|
||||||
|
@ -24,7 +24,7 @@ const sessionStorage = new LocalStorageController<{
|
|||||||
dc5_server_salt: string,
|
dc5_server_salt: string,
|
||||||
server_time_offset: number,
|
server_time_offset: number,
|
||||||
xt_instance: AppInstance,
|
xt_instance: AppInstance,
|
||||||
kz_version: 'k' | 'z'
|
kz_version: 'K' | 'Z'
|
||||||
}>(['kz_version']);
|
}>(/* ['kz_version'] */);
|
||||||
MOUNT_CLASS_TO.appStorage = sessionStorage;
|
MOUNT_CLASS_TO.appStorage = sessionStorage;
|
||||||
export default sessionStorage;
|
export default sessionStorage;
|
||||||
|
Loading…
Reference in New Issue
Block a user