Skip to content

Commit d19cf65

Browse files
committed
improve GUI
1 parent df1e3c1 commit d19cf65

File tree

1 file changed

+51
-25
lines changed

1 file changed

+51
-25
lines changed

src/gui.rs

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@ use tempfile::{Builder, NamedTempFile};
1414
use monolith::cache::Cache;
1515
use monolith::core::{create_monolithic_document, format_output_path, MonolithError, Options};
1616

17-
const CACHE_ASSET_FILE_SIZE_THRESHOLD: usize = 1024 * 10; // Minimum file size for on-disk caching (in bytes)
17+
const CACHE_ASSET_FILE_SIZE_THRESHOLD: usize = 1024 * 20; // Minimum file size for on-disk caching (in bytes)
1818

1919
struct Delegate;
2020

2121
#[derive(Clone, Data, Lens)]
2222
struct AppState {
23-
busy: bool,
24-
isolate: bool,
23+
target: String,
2524
keep_fonts: bool,
2625
keep_frames: bool,
2726
keep_images: bool,
2827
keep_scripts: bool,
2928
keep_styles: bool,
30-
target: String,
3129
output_path: String,
30+
isolate: bool,
31+
unwrap_noscript: bool,
32+
busy: bool,
3233
}
3334

3435
const MONOLITH_GUI_WRITE_OUTPUT: druid::Selector<(Vec<u8>, Option<String>)> =
@@ -41,17 +42,20 @@ fn main() -> Result<(), PlatformError> {
4142
if let Some(l) = program_name.get_mut(0..1) {
4243
l.make_ascii_uppercase();
4344
}
44-
let main_window = WindowDesc::new(ui_builder()).title(program_name);
45+
let main_window = WindowDesc::new(ui_builder())
46+
.title(program_name)
47+
.with_min_size((640., 320.));
4548
let state = AppState {
46-
busy: false,
47-
isolate: false,
49+
target: "".to_string(),
4850
keep_fonts: true,
4951
keep_frames: true,
5052
keep_images: true,
5153
keep_scripts: true,
5254
keep_styles: true,
53-
target: "".to_string(),
54-
output_path: "".to_string(),
55+
output_path: "".to_string(), // TODO: set it to ~/Downloads/%title%.html by default
56+
isolate: false,
57+
unwrap_noscript: false,
58+
busy: false,
5559
};
5660

5761
AppLauncher::with_window(main_window)
@@ -61,18 +65,22 @@ fn main() -> Result<(), PlatformError> {
6165

6266
fn ui_builder() -> impl Widget<AppState> {
6367
let target_input = TextBox::new()
64-
.with_placeholder("URL (http:, https:, file:, data:) or local filesystem path")
68+
.with_placeholder("Target (http:/https:/file:/data: URL) or filesystem path")
6569
.lens(AppState::target)
6670
.disabled_if(|state: &AppState, _env| state.busy);
67-
let text = LocalizedString::new("hello-counter").with_arg("count", |state: &AppState, _env| {
68-
state.output_path.clone().into()
69-
});
70-
let label = Label::new(text).center();
71-
let output_path_button = Button::new(LocalizedString::new("browse"))
71+
let target_button = Button::new(LocalizedString::new("Open file"))
7272
.on_click(|ctx, _, _| {
73-
ctx.submit_command(commands::SHOW_SAVE_PANEL.with(
74-
FileDialogOptions::new().default_name("%title% - %timestamp%.html"), // .lens(AppState::output_path)
75-
))
73+
ctx.submit_command(commands::SHOW_OPEN_PANEL.with(FileDialogOptions::new()))
74+
})
75+
.disabled_if(|state: &AppState, _env| state.busy);
76+
let output_path_label: Label<AppState> =
77+
Label::new(|state: &AppState, _env: &_| format!("Output path: {}", state.output_path));
78+
let output_path_button = Button::new(LocalizedString::new("Browse"))
79+
.on_click(|ctx, _, _| {
80+
ctx.submit_command(
81+
commands::SHOW_SAVE_PANEL
82+
.with(FileDialogOptions::new().default_name("%title% - %timestamp%.html")),
83+
)
7684
})
7785
.disabled_if(|state: &AppState, _env| state.busy);
7886
let fonts_checkbox = Checkbox::new("Fonts")
@@ -99,7 +107,11 @@ fn ui_builder() -> impl Widget<AppState> {
99107
.lens(AppState::isolate)
100108
.disabled_if(|state: &AppState, _env| state.busy)
101109
.padding(5.0);
102-
let button = Button::new(LocalizedString::new("start"))
110+
let unwrap_noscript_checkbox = Checkbox::new("Unwrap NOSCRIPTs")
111+
.lens(AppState::unwrap_noscript)
112+
.disabled_if(|state: &AppState, _env| state.busy)
113+
.padding(5.0);
114+
let start_stop_button = Button::new(LocalizedString::new("Start"))
103115
.on_click(|ctx, state: &mut AppState, _env| {
104116
if state.busy {
105117
return;
@@ -115,6 +127,7 @@ fn ui_builder() -> impl Widget<AppState> {
115127
options.no_css = !state.keep_styles;
116128
options.no_js = !state.keep_scripts;
117129
options.isolate = state.isolate;
130+
options.unwrap_noscript = state.unwrap_noscript;
118131

119132
let handle = ctx.get_external_handle();
120133
let thread_state = state.clone();
@@ -167,16 +180,27 @@ fn ui_builder() -> impl Widget<AppState> {
167180
});
168181

169182
Flex::column()
170-
.with_child(target_input)
171-
.with_child(label)
172-
.with_child(output_path_button)
183+
.with_child(
184+
Flex::row()
185+
.with_child(target_input)
186+
.with_child(target_button),
187+
)
173188
.with_child(fonts_checkbox)
174189
.with_child(frames_checkbox)
175190
.with_child(images_checkbox)
176191
.with_child(scripts_checkbox)
177192
.with_child(styles_checkbox)
178-
.with_child(isolate_checkbox)
179-
.with_child(button)
193+
.with_child(
194+
Flex::row()
195+
.with_child(output_path_label)
196+
.with_child(output_path_button),
197+
)
198+
.with_child(
199+
Flex::row()
200+
.with_child(isolate_checkbox)
201+
.with_child(unwrap_noscript_checkbox),
202+
)
203+
.with_child(start_stop_button)
180204
}
181205

182206
impl AppDelegate<AppState> for Delegate {
@@ -216,7 +240,9 @@ impl AppDelegate<AppState> for Delegate {
216240
return Handled::Yes;
217241
}
218242

219-
if let Some(_file_info) = cmd.get(commands::OPEN_FILE) {
243+
if let Some(file_info) = cmd.get(commands::OPEN_FILE) {
244+
state.target = file_info.path().display().to_string();
245+
220246
return Handled::Yes;
221247
}
222248

0 commit comments

Comments
 (0)