fix: crash when database is not exist

This commit is contained in:
reya
2024-03-08 14:47:36 +07:00
parent a4fdcfdf0b
commit a3e46aa96b
8 changed files with 14 additions and 13 deletions

View File

@@ -45,7 +45,8 @@ function Inactive({ pubkey }: { pubkey: string }) {
const changeAccount = async (npub: string) => { const changeAccount = async (npub: string) => {
const select = await ark.load_selected_account(npub); const select = await ark.load_selected_account(npub);
if (select) navigate({ to: "/$account/home", params: { account: npub } }); if (select)
navigate({ to: "/$account/home/local", params: { account: npub } });
}; };
return ( return (

View File

@@ -104,7 +104,7 @@ export function BackupDialog() {
</button> </button>
) : ( ) : (
<Link <Link
to="/$account/home" to="/$account/home/local"
params={{ account }} params={{ account }}
search={{ guest: false }} search={{ guest: false }}
className="inline-flex h-11 w-full items-center justify-center gap-1.5 rounded-lg bg-blue-500 px-5 font-medium text-white hover:bg-blue-600" className="inline-flex h-11 w-full items-center justify-center gap-1.5 rounded-lg bg-blue-500 px-5 font-medium text-white hover:bg-blue-600"

View File

@@ -68,7 +68,7 @@ function Navigation() {
data-tauri-drag-region data-tauri-drag-region
className="flex h-full flex-1 items-center gap-2" className="flex h-full flex-1 items-center gap-2"
> >
<Link to="/$account/home" params={{ account }}> <Link to="/$account/home/local" params={{ account }}>
{({ isActive }) => ( {({ isActive }) => (
<div <div
className={cn( className={cn(

View File

@@ -4,7 +4,7 @@ import { useQueryClient } from "@tanstack/react-query";
import { Link } from "@tanstack/react-router"; import { Link } from "@tanstack/react-router";
import { Outlet, createFileRoute } from "@tanstack/react-router"; import { Outlet, createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/$account/home")({ export const Route = createFileRoute("/$account/home/local")({
component: Screen, component: Screen,
}); });

View File

@@ -26,7 +26,7 @@ function Create() {
try { try {
await ark.save_account(keys); await ark.save_account(keys);
navigate({ navigate({
to: "/$account/home", to: "/$account/home/local",
params: { account: keys.npub }, params: { account: keys.npub },
search: { onboarding: true }, search: { onboarding: true },
replace: true, replace: true,

View File

@@ -32,7 +32,7 @@ function Import() {
nsec: key, nsec: key,
}); });
navigate({ navigate({
to: "/$account/home", to: "/$account/home/local",
params: { account: npub }, params: { account: npub },
search: { onboarding: true }, search: { onboarding: true },
replace: true, replace: true,

View File

@@ -15,7 +15,7 @@ export const Route = createFileRoute("/")({
case 0: case 0:
const guest = await ark.create_guest_account(); const guest = await ark.create_guest_account();
throw redirect({ throw redirect({
to: "/$account/home", to: "/$account/home/local",
params: { account: guest }, params: { account: guest },
search: { guest: true }, search: { guest: true },
replace: true, replace: true,
@@ -26,7 +26,7 @@ export const Route = createFileRoute("/")({
const loadAccount = await ark.load_selected_account(account); const loadAccount = await ark.load_selected_account(account);
if (loadAccount) { if (loadAccount) {
throw redirect({ throw redirect({
to: "/$account/home", to: "/$account/home/local",
params: { account }, params: { account },
replace: true, replace: true,
}); });

View File

@@ -22,7 +22,6 @@ fn main() {
.setup(|app| { .setup(|app| {
let _tray = tray::create_tray(app.handle()).unwrap(); let _tray = tray::create_tray(app.handle()).unwrap();
let handle = app.handle().clone(); let handle = app.handle().clone();
let resource_dir = handle.path().resource_dir().unwrap();
let home_dir = handle.path().home_dir().unwrap(); let home_dir = handle.path().home_dir().unwrap();
// create data folder if not exist // create data folder if not exist
@@ -30,12 +29,13 @@ fn main() {
tauri::async_runtime::spawn(async move { tauri::async_runtime::spawn(async move {
// Create nostr database connection // Create nostr database connection
let nostr_db = SQLiteDatabase::open(resource_dir.join("lume.db")) let sqlite = SQLiteDatabase::open(home_dir.join("Lume/lume.db")).await;
.await
.expect("Open database failed.");
// Create nostr connection // Create nostr connection
let client = ClientBuilder::default().database(nostr_db).build(); let client = match sqlite {
Ok(db) => ClientBuilder::default().database(db).build(),
Err(_) => ClientBuilder::default().build(),
};
// Add some bootstrap relays // Add some bootstrap relays
// #TODO: Pull bootstrap relays from user's settings // #TODO: Pull bootstrap relays from user's settings