support file picking and uploads on web
This commit is contained in:
+21
-8
@@ -221,25 +221,38 @@ impl DeviceRegistry {
|
||||
cx.emit(DeviceEvent::Set);
|
||||
}
|
||||
|
||||
/// Backup the encryption's secret key to a file
|
||||
pub fn backup(&self, path: PathBuf, cx: &App) -> Task<Result<(), Error>> {
|
||||
/// Backup the encryption's secret key, returning the `nsec1...` content
|
||||
pub fn backup_bytes(&self, cx: &App) -> Task<Result<String, Error>> {
|
||||
let nostr = NostrRegistry::global(cx);
|
||||
let client = nostr.read(cx).client();
|
||||
let signer = nostr.read(cx).signer();
|
||||
|
||||
cx.background_spawn(async move {
|
||||
let keys = get_keys(&client, &signer).await?;
|
||||
let content = keys.secret_key().to_bech32()?;
|
||||
Ok(keys.secret_key().to_bech32()?)
|
||||
})
|
||||
}
|
||||
|
||||
if cfg!(target_arch = "wasm32") {
|
||||
return Err(anyhow!("Not supported"));
|
||||
}
|
||||
/// Backup the encryption's secret key to a file
|
||||
pub fn backup(&self, path: PathBuf, cx: &App) -> Task<Result<(), Error>> {
|
||||
let backup = self.backup_bytes(cx);
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
return cx.background_spawn(async move {
|
||||
let content = backup.await?;
|
||||
smol::fs::write(path, &content).await?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
});
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
let _ = path;
|
||||
cx.background_spawn(async move {
|
||||
backup.await?;
|
||||
Err(anyhow!("File backups are not supported on web; copy the key from the backup panel instead."))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Get device announcement for current user
|
||||
|
||||
Reference in New Issue
Block a user