feat: add support for launch arguments (#40)

Reviewed-on: #40
This commit was merged in pull request #40.
This commit is contained in:
2026-08-02 07:10:44 +00:00
parent 4f52fc52df
commit dbfee32d55
7 changed files with 64 additions and 57 deletions

View File

@@ -48,3 +48,4 @@ reqwest_client.workspace = true
log.workspace = true
tracing-subscriber.workspace = true
nostr-sdk.workspace = true

View File

@@ -7,6 +7,7 @@ use gpui::{
actions, point, px, size,
};
use gpui_platform::application;
use nostr_sdk::prelude::SecretKey;
use state::{APP_ID, CLIENT_NAME};
use ui::Root;
@@ -16,6 +17,14 @@ fn main() {
// Initialize logging
tracing_subscriber::fmt::init();
// Parse CLI arguments for --sec <nsec1>
let cli_key = parse_cli_key();
if let Err(ref e) = cli_key {
eprintln!("Failed to parse --sec argument: {e}");
std::process::exit(1);
}
let cli_key = cli_key.unwrap();
// Run application
application()
.with_assets(Assets)
@@ -75,7 +84,7 @@ fn main() {
settings::init(window, cx);
// Initialize the nostr client
state::init(window, cx);
state::init(window, cx, cli_key);
// Initialize person registry
person::init(window, cx);
@@ -125,6 +134,25 @@ fn load_embedded_fonts(cx: &App) {
.unwrap();
}
fn parse_cli_key() -> Result<Option<SecretKey>, String> {
let args: Vec<String> = std::env::args().collect();
let mut i = 0;
while i < args.len() {
if args[i] == "--sec" {
if i + 1 < args.len() {
let nsec = &args[i + 1];
return SecretKey::parse(nsec)
.map(Some)
.map_err(|e| format!("Invalid nsec key '{nsec}': {e}"));
} else {
return Err("--sec requires a value (nsec1...)".to_string());
}
}
i += 1;
}
Ok(None)
}
fn quit(_ev: &Quit, cx: &mut App) {
log::info!("Gracefully quitting the application . . .");
cx.quit();