This commit is contained in:
Ren Amamiya
2023-09-24 07:55:27 +07:00
parent c9bc7b81dd
commit 50f90ddcc2
12 changed files with 510 additions and 351 deletions

View File

@@ -1,6 +1,5 @@
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { BaseDirectory, removeFile } from '@tauri-apps/api/fs';
import { Platform } from '@tauri-apps/api/os';
import Database from 'tauri-plugin-sql-api';
import { Stronghold } from 'tauri-plugin-stronghold-api';
@@ -11,13 +10,11 @@ import { Account, DBEvent, Relays, Widget } from '@utils/types';
export class LumeStorage {
public db: Database;
public platform: Platform;
public secureDB: Stronghold;
public account: Account | null = null;
constructor(sqlite: Database, platform: Platform, stronghold?: Stronghold) {
constructor(sqlite: Database, stronghold?: Stronghold) {
this.db = sqlite;
this.platform = platform ?? undefined;
this.secureDB = stronghold ?? undefined;
this.account = null;
}
@@ -59,6 +56,13 @@ export class LumeStorage {
return await removeFile('lume.stronghold', { dir: BaseDirectory.AppConfig });
}
public async checkAccount() {
const result: Array<Account> = await this.db.select(
'SELECT * FROM accounts WHERE is_active = 1;'
);
return result.length > 0;
}
public async getActiveAccount() {
const results: Array<Account> = await this.db.select(
'SELECT * FROM accounts WHERE is_active = "1" ORDER BY id DESC LIMIT 1;'