@@ -14,21 +14,22 @@ use tempfile::{Builder, NamedTempFile};
14
14
use monolith:: cache:: Cache ;
15
15
use monolith:: core:: { create_monolithic_document, format_output_path, MonolithError , Options } ;
16
16
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)
18
18
19
19
struct Delegate ;
20
20
21
21
#[ derive( Clone , Data , Lens ) ]
22
22
struct AppState {
23
- busy : bool ,
24
- isolate : bool ,
23
+ target : String ,
25
24
keep_fonts : bool ,
26
25
keep_frames : bool ,
27
26
keep_images : bool ,
28
27
keep_scripts : bool ,
29
28
keep_styles : bool ,
30
- target : String ,
31
29
output_path : String ,
30
+ isolate : bool ,
31
+ unwrap_noscript : bool ,
32
+ busy : bool ,
32
33
}
33
34
34
35
const MONOLITH_GUI_WRITE_OUTPUT : druid:: Selector < ( Vec < u8 > , Option < String > ) > =
@@ -41,17 +42,20 @@ fn main() -> Result<(), PlatformError> {
41
42
if let Some ( l) = program_name. get_mut ( 0 ..1 ) {
42
43
l. make_ascii_uppercase ( ) ;
43
44
}
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. ) ) ;
45
48
let state = AppState {
46
- busy : false ,
47
- isolate : false ,
49
+ target : "" . to_string ( ) ,
48
50
keep_fonts : true ,
49
51
keep_frames : true ,
50
52
keep_images : true ,
51
53
keep_scripts : true ,
52
54
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 ,
55
59
} ;
56
60
57
61
AppLauncher :: with_window ( main_window)
@@ -61,18 +65,22 @@ fn main() -> Result<(), PlatformError> {
61
65
62
66
fn ui_builder ( ) -> impl Widget < AppState > {
63
67
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" )
65
69
. lens ( AppState :: target)
66
70
. 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" ) )
72
72
. 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
+ )
76
84
} )
77
85
. disabled_if ( |state : & AppState , _env| state. busy ) ;
78
86
let fonts_checkbox = Checkbox :: new ( "Fonts" )
@@ -99,7 +107,11 @@ fn ui_builder() -> impl Widget<AppState> {
99
107
. lens ( AppState :: isolate)
100
108
. disabled_if ( |state : & AppState , _env| state. busy )
101
109
. 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" ) )
103
115
. on_click ( |ctx, state : & mut AppState , _env| {
104
116
if state. busy {
105
117
return ;
@@ -115,6 +127,7 @@ fn ui_builder() -> impl Widget<AppState> {
115
127
options. no_css = !state. keep_styles ;
116
128
options. no_js = !state. keep_scripts ;
117
129
options. isolate = state. isolate ;
130
+ options. unwrap_noscript = state. unwrap_noscript ;
118
131
119
132
let handle = ctx. get_external_handle ( ) ;
120
133
let thread_state = state. clone ( ) ;
@@ -167,16 +180,27 @@ fn ui_builder() -> impl Widget<AppState> {
167
180
} ) ;
168
181
169
182
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
+ )
173
188
. with_child ( fonts_checkbox)
174
189
. with_child ( frames_checkbox)
175
190
. with_child ( images_checkbox)
176
191
. with_child ( scripts_checkbox)
177
192
. 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)
180
204
}
181
205
182
206
impl AppDelegate < AppState > for Delegate {
@@ -216,7 +240,9 @@ impl AppDelegate<AppState> for Delegate {
216
240
return Handled :: Yes ;
217
241
}
218
242
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
+
220
246
return Handled :: Yes ;
221
247
}
222
248
0 commit comments