wip
This commit is contained in:
@@ -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;'
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { message } from '@tauri-apps/api/dialog';
|
||||
import { platform } from '@tauri-apps/api/os';
|
||||
import { appConfigDir } from '@tauri-apps/api/path';
|
||||
import { PropsWithChildren, createContext, useContext, useEffect, useState } from 'react';
|
||||
import Database from 'tauri-plugin-sql-api';
|
||||
|
||||
@@ -17,14 +15,10 @@ const StorageContext = createContext<StorageContext>({
|
||||
const StorageProvider = ({ children }: PropsWithChildren<object>) => {
|
||||
const [db, setDB] = useState<LumeStorage>(undefined);
|
||||
|
||||
async function initLumeStorage() {
|
||||
const initLumeStorage = async () => {
|
||||
try {
|
||||
const dir = await appConfigDir();
|
||||
const sqlite = await Database.load('sqlite:lume.db');
|
||||
const platformName = await platform();
|
||||
const lumeStorage = new LumeStorage(sqlite, platformName);
|
||||
|
||||
console.log('App config dir: ', dir);
|
||||
const lumeStorage = new LumeStorage(sqlite);
|
||||
|
||||
if (!lumeStorage.account) await lumeStorage.getActiveAccount();
|
||||
setDB(lumeStorage);
|
||||
@@ -34,7 +28,7 @@ const StorageProvider = ({ children }: PropsWithChildren<object>) => {
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!db) initLumeStorage();
|
||||
|
||||
Reference in New Issue
Block a user