feat(ui): setup single-instance (#2093)

This commit is contained in:
Ellie Huxtable 2024-06-06 10:36:39 +01:00 committed by GitHub
parent c102851e29
commit d7f77ebfe1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 877 additions and 317 deletions

1104
ui/backend/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -12,8 +12,8 @@ edition = "2021"
tauri-build = { version = "2.0.0-beta", features = [] }
[dependencies]
atuin-client = { path = "../../crates/atuin-client", version = "18.2.0" }
atuin-common = { path = "../../crates/atuin-common", version = "18.2.0" }
atuin-client = { path = "../../crates/atuin-client", version = "18.3.0-prerelease.1" }
atuin-common = { path = "../../crates/atuin-common", version = "18.3.0-prerelease.1" }
atuin-dotfiles = { path = "../../crates/atuin-dotfiles", version = "0.2.0" }
atuin-history = { path = "../../crates/atuin-history", version = "0.1.0" }
@ -25,6 +25,7 @@ time = "0.3.36"
uuid = "1.7.0"
syntect = "5.2.0"
tauri-plugin-http = "2.0.0-beta"
tauri-plugin-single-instance = "2.0.0-beta.9"
[dependencies.sqlx]
version = "0.7"

View File

@ -2,14 +2,15 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use std::path::PathBuf;
use time::format_description::well_known::Rfc3339;
use atuin_client::settings::Settings;
use tauri::{AppHandle, Manager};
use time::format_description::well_known::Rfc3339;
mod db;
mod dotfiles;
mod store;
use atuin_client::settings::Settings;
use atuin_client::{
encryption, history::HISTORY_TAG, record::sqlite_store::SqliteStore, record::store::Store,
};
@ -165,6 +166,17 @@ async fn home_info() -> Result<HomeInfo, String> {
Ok(info)
}
fn show_window(app: &AppHandle) {
let windows = app.webview_windows();
windows
.values()
.next()
.expect("Sorry, no window found")
.set_focus()
.expect("Can't Bring Window to Focus");
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
@ -186,6 +198,9 @@ fn main() {
])
.plugin(tauri_plugin_sql::Builder::default().build())
.plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_single_instance::init(|app, args, cwd| {
let _ = show_window(app);
}))
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

51
ui/backend/src/update.rs Normal file
View File

@ -0,0 +1,51 @@
// While technically using a "self update" crate, we can actually use the same method
// for managing a CLI install. Neat!
// This should still be locked to the same version as the UI. Drift there could lead to issues.
// In the future we can follow semver and allow for minor version drift.
// If you'd like to follow the conventions of your OS, distro, etc, then I would suggest
// following the CLI install instructions. This is intended to streamline install UX
use eyre::{eyre, Result};
use std::{
ffi::{OsStr, OsString},
path::Path,
};
pub fn install(version: &str, path: &str) -> Result<()> {
let dir = std::path::PathBuf::from(path);
std::fs::create_dir_all(path)?;
let bin = dir.join("atuin");
let releases = self_update::backends::github::ReleaseList::configure()
.repo_owner("atuinsh")
.repo_name("atuin")
.build()?
.fetch()?;
let release = releases
.iter()
.find(|r| r.version == version)
.ok_or_else(|| eyre!("No release found for version: {}", version))?;
let asset = release
.asset_for(&self_update::get_target(), None)
.ok_or_else(|| eyre!("No asset found for target"))?;
let tmp_dir = tempfile::Builder::new().prefix("atuin").tempdir()?;
let tmp_tarball_path = tmp_dir.path().join(&asset.name);
let tmp_tarball = std::fs::File::create(&tmp_tarball_path)?;
println!("{:?}", tmp_tarball_path);
self_update::Download::from_url(&asset.download_url).download_to(&tmp_tarball)?;
let root = asset.name.replace(".tar.gz", "");
let bin_name = std::path::PathBuf::from(format!("{}/atuin", root,));
self_update::Extract::from_source(&tmp_tarball_path)
.archive(self_update::ArchiveKind::Tar(Some(
self_update::Compression::Gz,
)))
.extract_file(&bin, &bin_name)?;
Ok(())
}

View File

@ -5,17 +5,9 @@ import { useStore } from "@/state/store";
import Button, { ButtonStyle } from "@/components/Button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
import {
Cog6ToothIcon,
HomeIcon,
ClockIcon,
WrenchScrewdriverIcon,

View File

@ -25,7 +25,7 @@ function Login(props: LoginProps) {
await login(username, password, key);
refreshUser();
console.log("Logged in");
} catch (e) {
} catch (e: any) {
console.error(e);
setErrors(e);
}
@ -190,7 +190,7 @@ function Register(props: RegisterProps) {
await register(username, email, password);
refreshUser();
console.log("Logged in");
} catch (e) {
} catch (e: any) {
console.error(e);
setErrors(e);
}

View File

@ -11,7 +11,6 @@ import {
Alias,
ShellHistory,
Var,
Settings,
} from "./models";
import { invoke } from "@tauri-apps/api/core";