@@ -105,12 +105,9 @@ impl Application {
105
105
} )
106
106
}
107
107
108
- pub fn window ( & self ) -> Option < Window > {
109
- self . active_window ( ) . and_downcast ( ) . or_else ( || {
110
- self . windows ( )
111
- . into_iter ( )
112
- . find_map ( |w| w. downcast :: < Window > ( ) . ok ( ) )
113
- } )
108
+ pub fn window ( & self ) -> Window {
109
+ self . active_window ( )
110
+ . map_or_else ( || Window :: new ( self ) , |w| w. downcast ( ) . unwrap ( ) )
114
111
}
115
112
116
113
pub fn send_record_success_notification ( & self , recording_file : & gio:: File ) {
@@ -131,12 +128,8 @@ impl Application {
131
128
}
132
129
133
130
pub fn present_preferences_dialog ( & self ) {
134
- if let Some ( window) = self . window ( ) {
135
- let dialog = PreferencesDialog :: new ( self . settings ( ) ) ;
136
- dialog. present ( & window) ;
137
- } else {
138
- tracing:: warn!( "Can't present preferences dialog without an active window" ) ;
139
- }
131
+ let dialog = PreferencesDialog :: new ( self . settings ( ) ) ;
132
+ dialog. present ( & self . window ( ) ) ;
140
133
}
141
134
142
135
pub fn run ( & self ) -> glib:: ExitCode {
@@ -156,7 +149,9 @@ impl Application {
156
149
}
157
150
158
151
async fn quit_request ( & self ) -> glib:: Propagation {
159
- if let Some ( window) = self . window ( ) {
152
+ if let Some ( window) = self . active_window ( ) {
153
+ let window = window. downcast :: < Window > ( ) . unwrap ( ) ;
154
+
160
155
if window. is_busy ( ) {
161
156
return window. run_quit_confirmation_dialog ( ) . await ;
162
157
}
@@ -166,18 +161,14 @@ impl Application {
166
161
}
167
162
168
163
async fn try_show_uri ( & self , uri : & str ) {
164
+ let window = self . window ( ) ;
169
165
if let Err ( err) = gtk:: FileLauncher :: new ( Some ( & gio:: File :: for_uri ( uri) ) )
170
- . launch_future ( self . window ( ) . as_ref ( ) )
166
+ . launch_future ( Some ( & window ) )
171
167
. await
172
168
{
173
169
if !err. matches ( gio:: IOErrorEnum :: Cancelled ) {
174
170
tracing:: error!( "Failed to launch default for uri `{}`: {:?}" , uri, err) ;
175
-
176
- if let Some ( window) = self . window ( ) {
177
- window. present_error_dialog ( & err. into ( ) ) ;
178
- } else {
179
- tracing:: error!( "No window to present error" ) ;
180
- }
171
+ window. present_error_dialog ( & err. into ( ) ) ;
181
172
}
182
173
}
183
174
}
@@ -203,7 +194,7 @@ impl Application {
203
194
204
195
glib:: spawn_future_local( async move {
205
196
if let Err ( err) = gtk:: FileLauncher :: new( Some ( & gio:: File :: for_uri( & uri) ) )
206
- . open_containing_folder_future( obj. window( ) . as_ref ( ) )
197
+ . open_containing_folder_future( Some ( & obj. window( ) ) )
207
198
. await
208
199
{
209
200
tracing:: warn!( "Failed to show items: {:?}" , err) ;
@@ -216,11 +207,7 @@ impl Application {
216
207
217
208
let action_show_about = gio:: SimpleAction :: new ( "show-about" , None ) ;
218
209
action_show_about. connect_activate ( clone ! ( @weak self as obj => move |_, _| {
219
- if let Some ( window) = obj. window( ) {
220
- about:: present_dialog( & window) ;
221
- } else {
222
- tracing:: warn!( "Can't present about dialog without an active window" ) ;
223
- }
210
+ about:: present_dialog( & obj. window( ) ) ;
224
211
} ) ) ;
225
212
self . add_action ( & action_show_about) ;
226
213
0 commit comments