Skip to content

Commit

Permalink
#95: Support configuring local secondary manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Dec 20, 2023
1 parent 8e87ad6 commit 789cd7e
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 42 deletions.
2 changes: 2 additions & 0 deletions lang/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ label-custom = Custom
label-none = None
label-change-count = Changes: {$total}
label-unscanned = Unscanned
# This refers to a local file on the computer
label-file = File
store-ea = EA
store-epic = Epic
Expand Down
34 changes: 28 additions & 6 deletions src/gui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,11 +1331,11 @@ impl Application for App {
match action {
EditAction::Add => {
self.text_histories.secondary_manifests.push(Default::default());
self.config.manifest.secondary.push("".to_string());
self.config.manifest.secondary.push(Default::default());
}
EditAction::Change(index, value) => {
self.text_histories.secondary_manifests[index].push(&value);
self.config.manifest.secondary[index] = value;
self.config.manifest.secondary[index].set(value);
}
EditAction::Remove(index) => {
self.text_histories.secondary_manifests.remove(index);
Expand All @@ -1360,6 +1360,11 @@ impl Application for App {
self.config.save();
Command::none()
}
Message::SelectedSecondaryManifestKind(index, kind) => {
self.config.manifest.secondary[index].convert(kind);
self.config.save();
Command::none()
}
Message::EditedRedirect(action, field) => {
match action {
EditAction::Add => {
Expand Down Expand Up @@ -1826,6 +1831,10 @@ impl Application for App {
self.text_histories.rclone_executable.push(&path.raw());
self.config.apps.rclone.path = path;
}
BrowseFileSubject::SecondaryManifest(i) => {
self.text_histories.secondary_manifests[i].push(&path.raw());
self.config.manifest.secondary[i].set(path.raw());
}
}
self.config.save();
Command::none()
Expand Down Expand Up @@ -1905,6 +1914,12 @@ impl Application for App {
Message::OpenFileSubject(subject) => {
let path = match subject {
BrowseFileSubject::RcloneExecutable => self.config.apps.rclone.path.clone(),
BrowseFileSubject::SecondaryManifest(i) => {
let Some(path) = self.config.manifest.secondary[i].path() else {
return Command::none();
};
path.clone()
}
};

match path.parent_if_file() {
Expand Down Expand Up @@ -1957,10 +1972,17 @@ impl Application for App {
),
UndoSubject::Root(i) => shortcut
.apply_to_strict_path_field(&mut self.config.roots[i].path, &mut self.text_histories.roots[i]),
UndoSubject::SecondaryManifest(i) => shortcut.apply_to_string_field(
&mut self.config.manifest.secondary[i],
&mut self.text_histories.secondary_manifests[i],
),
UndoSubject::SecondaryManifest(i) => {
let history = &mut self.text_histories.secondary_manifests[i];
match shortcut {
Shortcut::Undo => {
self.config.manifest.secondary[i].set(history.undo());
}
Shortcut::Redo => {
self.config.manifest.secondary[i].set(history.redo());
}
}
}
UndoSubject::RedirectSource(i) => shortcut.apply_to_strict_path_field(
&mut self.config.redirects[i].source,
&mut self.text_histories.redirects[i].source,
Expand Down
6 changes: 5 additions & 1 deletion src/gui/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::{
lang::{Language, TRANSLATOR},
prelude::{CommandError, Error, Finality, Privacy, StrictPath, SyncDirection},
resource::{
config::{BackupFormat, RedirectKind, RootsConfig, SortKey, Theme, ZipCompression},
config::{
BackupFormat, RedirectKind, RootsConfig, SecondaryManifestConfigKind, SortKey, Theme, ZipCompression,
},
manifest::{Manifest, ManifestUpdate, Store},
},
scan::{
Expand Down Expand Up @@ -118,6 +120,7 @@ pub enum Message {
EditedSecondaryManifest(EditAction),
SelectedRootStore(usize, Store),
SelectedRedirectKind(usize, RedirectKind),
SelectedSecondaryManifestKind(usize, SecondaryManifestConfigKind),
EditedRedirect(EditAction, Option<RedirectEditActionField>),
EditedCustomGame(EditAction),
EditedCustomGameFile(usize, EditAction),
Expand Down Expand Up @@ -607,6 +610,7 @@ pub enum BrowseSubject {
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BrowseFileSubject {
RcloneExecutable,
SecondaryManifest(usize),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down
51 changes: 32 additions & 19 deletions src/gui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use iced::{
use crate::{
gui::{
button,
common::{BackupPhase, BrowseSubject, Message, ScrollSubject, UndoSubject},
common::{BackupPhase, BrowseFileSubject, BrowseSubject, Message, ScrollSubject, UndoSubject},
shortcuts::TextHistories,
style,
widget::{checkbox, pick_list, text, Column, Container, IcedParentExt, Row, Tooltip},
},
lang::TRANSLATOR,
resource::{
cache::Cache,
config::{Config, RedirectKind},
config::{Config, RedirectKind, SecondaryManifestConfigKind},
manifest::Store,
},
};
Expand Down Expand Up @@ -52,12 +52,17 @@ pub fn root<'a>(config: &Config, histories: &TextHistories, modifiers: &keyboard
Container::new(content)
}

pub fn manifest<'a>(config: &Config, cache: &'a Cache, histories: &TextHistories) -> Container<'a> {
pub fn manifest<'a>(
config: &Config,
cache: &'a Cache,
histories: &TextHistories,
modifiers: &keyboard::Modifiers,
) -> Container<'a> {
let label_width = Length::Fixed(160.0);
let left_offset = Length::Fixed(70.0);
let right_offset = Length::Fixed(70.0);

let get_checked = |url: &str, cache: &'a Cache| {
let get_checked = |url: Option<&str>, cache: &'a Cache| {
let url = url?;
let cached = cache.manifests.get(url)?;
let checked = match cached.checked {
Some(x) => chrono::DateTime::<chrono::Local>::from(x)
Expand All @@ -68,7 +73,8 @@ pub fn manifest<'a>(config: &Config, cache: &'a Cache, histories: &TextHistories
Some(Container::new(text(checked)).width(label_width))
};

let get_updated = |url: &str, cache: &'a Cache| {
let get_updated = |url: Option<&str>, cache: &'a Cache| {
let url = url?;
let cached = cache.manifests.get(url)?;
let updated = match cached.updated {
Some(x) => chrono::DateTime::<chrono::Local>::from(x)
Expand All @@ -86,11 +92,7 @@ pub fn manifest<'a>(config: &Config, cache: &'a Cache, histories: &TextHistories
Row::new()
.spacing(20)
.align_items(Alignment::Center)
.push_if(
|| !config.manifest.secondary.is_empty(),
|| Space::with_width(left_offset),
)
.push(text(TRANSLATOR.url_label()).width(Length::Fill))
.push(Space::with_width(Length::Fill))
.push(Container::new(text(TRANSLATOR.checked_label())).width(label_width))
.push(Container::new(text(TRANSLATOR.updated_label())).width(label_width))
.push_if(
Expand All @@ -102,13 +104,9 @@ pub fn manifest<'a>(config: &Config, cache: &'a Cache, histories: &TextHistories
Row::new()
.spacing(20)
.align_items(Alignment::Center)
.push_if(
|| !config.manifest.secondary.is_empty(),
|| Space::with_width(left_offset),
)
.push(iced::widget::TextInput::new("", &config.manifest.url).width(Length::Fill))
.push_some(|| get_checked(&config.manifest.url, cache))
.push_some(|| get_updated(&config.manifest.url, cache))
.push_some(|| get_checked(Some(&config.manifest.url), cache))
.push_some(|| get_updated(Some(&config.manifest.url), cache))
.push_if(
|| !config.manifest.secondary.is_empty(),
|| Space::with_width(right_offset),
Expand All @@ -131,9 +129,24 @@ pub fn manifest<'a>(config: &Config, cache: &'a Cache, histories: &TextHistories
i,
config.manifest.secondary.len(),
))
.push(
pick_list(
SecondaryManifestConfigKind::ALL,
Some(config.manifest.secondary[i].kind()),
move |v| Message::SelectedSecondaryManifestKind(i, v),
)
.style(style::PickList::Primary)
.width(75),
)
.push(histories.input(UndoSubject::SecondaryManifest(i)))
.push_some(|| get_checked(&config.manifest.secondary[i], cache))
.push_some(|| get_updated(&config.manifest.secondary[i], cache))
.push_some(|| get_checked(config.manifest.secondary[i].url(), cache))
.push_some(|| get_updated(config.manifest.secondary[i].url(), cache))
.push_some(|| match config.manifest.secondary[i].kind() {
SecondaryManifestConfigKind::Local => {
Some(button::choose_file(BrowseFileSubject::SecondaryManifest(i), modifiers))
}
SecondaryManifestConfigKind::Remote => None,
})
.push(button::remove(Message::EditedSecondaryManifest, i)),
)
});
Expand Down
2 changes: 1 addition & 1 deletion src/gui/modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub enum ModalField {
impl ModalField {
pub fn view<'a>(kind: ModalInputKind, histories: &TextHistories) -> Row<'a> {
let label = match kind {
ModalInputKind::Url => TRANSLATOR.url_label(),
ModalInputKind::Url => TRANSLATOR.url_field(),
ModalInputKind::Host => TRANSLATOR.host_label(),
ModalInputKind::Port => TRANSLATOR.port_label(),
ModalInputKind::Username => TRANSLATOR.username_label(),
Expand Down
2 changes: 1 addition & 1 deletion src/gui/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ pub fn other<'a>(
.push(text(TRANSLATOR.manifest_label()).width(100))
.push(button::refresh(Message::UpdateManifest, updating_manifest)),
)
.push(editor::manifest(config, cache, histories).padding([10, 0, 0, 0])),
.push(editor::manifest(config, cache, histories, modifiers).padding([10, 0, 0, 0])),
)
.push(
Column::new()
Expand Down
2 changes: 1 addition & 1 deletion src/gui/shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl TextHistories {
}

for x in &config.manifest.secondary {
histories.secondary_manifests.push(TextHistory::raw(x));
histories.secondary_manifests.push(TextHistory::raw(&x.value()));
}

for x in &config.redirects {
Expand Down
8 changes: 8 additions & 0 deletions src/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,15 @@ impl Translator {
translate("label-arguments")
}

pub fn file_label(&self) -> String {
translate("label-file")
}

pub fn url_label(&self) -> String {
translate("label-url")
}

pub fn url_field(&self) -> String {
self.field(&translate("label-url"))
}

Expand Down
5 changes: 5 additions & 0 deletions src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ where
Self::load_from_string(&content)
}

fn load_from_existing(path: &std::path::PathBuf) -> Result<Self, AnyError> {
let content = Self::load_raw(path)?;
Self::load_from_string(&content)
}

fn load_raw(path: &std::path::PathBuf) -> Result<String, AnyError> {
Ok(std::fs::read_to_string(path)?)
}
Expand Down
Loading

0 comments on commit 789cd7e

Please sign in to comment.