Skip to content

Commit

Permalink
Improve robustness of choosing iOS' default file.
Browse files Browse the repository at this point in the history
Also display error if there are no files in the zip.
  • Loading branch information
awaitlink committed Oct 16, 2021
1 parent 400c6a3 commit faf9ae4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
rc::Rc,
};

use anyhow::Context;
use anyhow::{ensure, Context};
use derive_more::{Display, IsVariant};
use strum_macros::EnumIter;
use yew::{prelude::*, services::fetch::FetchTask, web_sys::HtmlInputElement};
Expand Down Expand Up @@ -227,13 +227,14 @@ impl Model {
files.insert(name, File::from_text(self.platform.unwrap(), text)?);
}

let active_filename = Rc::clone(
files
.keys()
.filter(|k| k.app_id == AppId::Signal)
.last()
.unwrap(),
);
ensure!(!files.is_empty(), "no files in zip"); // TODO: maybe should just be a notice instead of an error

let last_for_app_id = |app_id| files.keys().filter(|k| k.app_id == app_id).last();
let active_filename =
Rc::clone(last_for_app_id(AppId::Signal).unwrap_or_else(|| {
last_for_app_id(AppId::NotificationServiceExtension)
.unwrap_or_else(|| last_for_app_id(AppId::ShareAppExtension).unwrap())
}));

Ok(self
.state
Expand Down

0 comments on commit faf9ae4

Please sign in to comment.