mirror of
https://github.com/atuinsh/atuin.git
synced 2024-11-24 17:23:50 +01:00
fix(ui): handle being logged out gracefully (#2052)
* fix(ui): handle being logged out gracefully * use settings.logged_in
This commit is contained in:
parent
1bb63d0f5a
commit
b49c73de3e
8
ui/backend/Cargo.lock
generated
8
ui/backend/Cargo.lock
generated
@ -5249,9 +5249,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.34"
|
||||
version = "0.3.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749"
|
||||
checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"itoa 1.0.11",
|
||||
@ -5272,9 +5272,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.17"
|
||||
version = "0.2.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774"
|
||||
checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf"
|
||||
dependencies = [
|
||||
"num-conv",
|
||||
"time-core",
|
||||
|
@ -19,10 +19,10 @@ use dotfiles::aliases::aliases;
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
struct HomeInfo {
|
||||
pub username: String,
|
||||
pub record_count: u64,
|
||||
pub history_count: u64,
|
||||
pub last_sync: String,
|
||||
pub username: Option<String>,
|
||||
pub last_sync: Option<String>,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@ -88,38 +88,40 @@ async fn home_info() -> Result<HomeInfo, String> {
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
let client = atuin_client::api_client::Client::new(
|
||||
&settings.sync_address,
|
||||
settings.session_token().map_err(|e|e.to_string())?.as_str(),
|
||||
settings.network_connect_timeout,
|
||||
settings.network_timeout,
|
||||
)
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
let session_path = settings.session_path.as_str();
|
||||
let last_sync = Settings::last_sync()
|
||||
.map_err(|e| e.to_string())?
|
||||
.format(&Rfc3339)
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
let record_count = sqlite_store.len_all().await.map_err(|e| e.to_string())?;
|
||||
let history_count = sqlite_store
|
||||
.len_tag(HISTORY_TAG)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
let info = if !PathBuf::from(session_path).exists() {
|
||||
let info = if settings.logged_in() {
|
||||
HomeInfo {
|
||||
username: String::from(""),
|
||||
last_sync: last_sync.to_string(),
|
||||
username: None,
|
||||
last_sync: None,
|
||||
record_count,
|
||||
history_count,
|
||||
}
|
||||
} else {
|
||||
let client = atuin_client::api_client::Client::new(
|
||||
&settings.sync_address,
|
||||
settings.session_token().map_err(|e|e.to_string())?.as_str(),
|
||||
settings.network_connect_timeout,
|
||||
settings.network_timeout,
|
||||
)
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
let me = client.me().await.map_err(|e| e.to_string())?;
|
||||
|
||||
HomeInfo {
|
||||
username: me.username,
|
||||
last_sync: last_sync.to_string(),
|
||||
username: Some(me.username),
|
||||
last_sync: Some(last_sync.to_string()),
|
||||
record_count,
|
||||
history_count,
|
||||
}
|
||||
|
@ -68,7 +68,10 @@ export default function Home() {
|
||||
stats={[
|
||||
{
|
||||
name: "Last Sync",
|
||||
stat: formatRelative(homeInfo.lastSyncTime, new Date()),
|
||||
stat:
|
||||
(homeInfo.lastSyncTime &&
|
||||
formatRelative(homeInfo.lastSyncTime, new Date())) ||
|
||||
"Never",
|
||||
},
|
||||
{
|
||||
name: "Total history records",
|
||||
|
@ -11,7 +11,7 @@ export const DefaultUser: User = {
|
||||
export interface HomeInfo {
|
||||
historyCount: number;
|
||||
recordCount: number;
|
||||
lastSyncTime: Date;
|
||||
lastSyncTime: Date | null;
|
||||
}
|
||||
|
||||
export const DefaultHomeInfo: HomeInfo = {
|
||||
|
@ -77,7 +77,7 @@ export const useStore = create<AtuinState>()((set, get) => ({
|
||||
homeInfo: {
|
||||
historyCount: res.history_count,
|
||||
recordCount: res.record_count,
|
||||
lastSyncTime: parseISO(res.last_sync),
|
||||
lastSyncTime: (res.last_sync && parseISO(res.last_sync)) || null,
|
||||
},
|
||||
});
|
||||
})
|
||||
@ -88,7 +88,14 @@ export const useStore = create<AtuinState>()((set, get) => ({
|
||||
|
||||
refreshUser: async () => {
|
||||
let config = await settings();
|
||||
let session = await sessionToken();
|
||||
let session;
|
||||
|
||||
try {
|
||||
session = await sessionToken();
|
||||
} catch (e) {
|
||||
console.log("Not logged in, so not refreshing user");
|
||||
return;
|
||||
}
|
||||
let url = config.sync_address + "/api/v0/me";
|
||||
|
||||
let res = await fetch(url, {
|
||||
|
Loading…
Reference in New Issue
Block a user