11use crate :: commands:: Function ;
22use crate :: config:: Config ;
3- use crate :: utils:: get_config_file_path;
3+ use crate :: utils:: { get_config_file_path, get_installed_apps , read_config_file } ;
44use global_hotkey:: { GlobalHotKeyEvent , HotKeyState } ;
55use iced:: futures:: SinkExt ;
66use iced:: {
@@ -15,7 +15,6 @@ use iced::{
1515 } ,
1616 window:: { self , Id , Settings } ,
1717} ;
18- use std:: path:: Path ;
1918
2019#[ cfg( target_os = "macos" ) ]
2120use crate :: macos:: { focus_this_app, transform_process_to_ui_element} ;
@@ -146,9 +145,6 @@ pub fn default_settings() -> Settings {
146145 }
147146}
148147
149- #[ derive( Debug , Clone ) ]
150- pub struct Temp { }
151-
152148#[ derive( Debug , Clone ) ]
153149pub struct Tile {
154150 theme : iced:: Theme ,
@@ -174,7 +170,7 @@ impl Tile {
174170 #[ cfg( target_os = "windows" ) ]
175171 {
176172 // get normal settings and modify position
177- use crate :: utils :: open_on_focused_monitor;
173+ use crate :: windows :: open_on_focused_monitor;
178174 use iced:: window:: Position :: Specific ;
179175 let pos = open_on_focused_monitor ( ) ;
180176 settings. position = Specific ( pos) ;
@@ -195,38 +191,11 @@ impl Tile {
195191 }
196192 } ) ) ;
197193
198- let store_icons = config. theme . show_icons ;
199- let paths;
200- let user_local_path: String ;
201- #[ cfg( target_os = "macos" ) ]
202- {
203- user_local_path = std:: env:: var ( "HOME" ) . unwrap ( ) + "/Applications/" ;
204- paths = vec ! [
205- "/Applications/" ,
206- user_local_path. as_str( ) ,
207- "/System/Applications/" ,
208- "/System/Applications/Utilities/" ,
209- ] ;
210- }
211- #[ cfg( target_os = "windows" ) ]
212- {
213- paths = vec ! [ "C:\\ Program Files\\ " , "C:\\ Program Files (x86)\\ " ] ;
214- }
194+ // get config
195+ let path = get_config_file_path ( ) ;
196+ let config = read_config_file ( & path) . unwrap ( ) ;
215197
216- let mut options: Vec < App > = paths
217- . par_iter ( )
218- . map ( |path| {
219- #[ cfg( target_os = "macos" ) ]
220- {
221- get_installed_apps ( path, store_icons)
222- }
223- #[ cfg( target_os = "windows" ) ]
224- {
225- get_installed_windows_app ( Path :: new ( path) )
226- }
227- } )
228- . flatten ( )
229- . collect ( ) ;
198+ let mut options: Vec < App > = get_installed_apps ( & config) ;
230199
231200 options. extend ( config. shells . iter ( ) . map ( |x| x. to_app ( ) ) ) ;
232201 options. extend ( App :: basic_apps ( ) ) ;
@@ -259,17 +228,8 @@ impl Tile {
259228 focus_this_app ( ) ;
260229 }
261230
262- #[ cfg( target_os = "windows" ) ]
263- {
264- if let Some ( hwnd) = self . frontmost {
265- unsafe {
266- let _ = SetForegroundWindow ( hwnd) ;
267- }
268- }
269- }
270-
271231 self . focused = true ;
272- Task :: none ( )
232+ operation :: focus ( "query" )
273233 }
274234
275235 Message :: SearchQueryChanged ( input, id) => {
@@ -353,7 +313,7 @@ impl Tile {
353313 #[ cfg( target_os = "windows" ) ]
354314 {
355315 // get normal settings and modify position
356- use crate :: utils :: open_on_focused_monitor;
316+ use crate :: windows :: open_on_focused_monitor;
357317 use iced:: window:: Position :: Specific ;
358318 let pos = open_on_focused_monitor ( ) ;
359319 let mut settings = default_settings ( ) ;
@@ -589,55 +549,3 @@ fn handle_hotkeys() -> impl futures::Stream<Item = Message> {
589549 }
590550 } )
591551}
592-
593- #[ cfg( target_os = "windows" ) ]
594- fn get_installed_windows_app ( path : & Path ) -> Vec < App > {
595- use std:: ffi:: OsString ;
596-
597- let mut apps = Vec :: new ( ) ;
598-
599- let hkey = winreg:: RegKey :: predef ( winreg:: enums:: HKEY_LOCAL_MACHINE ) ;
600-
601- // where we can find installed applications
602- // src: https://stackoverflow.com/questions/2864984/how-to-programatically-get-the-list-of-installed-programs/2892848#2892848
603- let registers = [
604- hkey. open_subkey ( "SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Uninstall" )
605- . unwrap ( ) ,
606- hkey. open_subkey ( "SOFTWARE\\ Wow6432Node\\ Microsoft\\ Windows\\ CurrentVersion\\ Uninstall" )
607- . unwrap ( ) ,
608- ] ;
609-
610- registers. iter ( ) . for_each ( |reg| {
611- reg. enum_keys ( ) . for_each ( |key| {
612- // https://learn.microsoft.com/en-us/windows/win32/msi/uninstall-registry-key
613- let name = key. unwrap ( ) ;
614- let key = reg. open_subkey ( & name) . unwrap ( ) ;
615- let display_name = key. get_value ( "DisplayName" ) . unwrap_or ( OsString :: new ( ) ) ;
616-
617- // they might be useful one day ?
618- // let publisher = key.get_value("Publisher").unwrap_or(OsString::new());
619- // let version = key.get_value("DisplayVersion").unwrap_or(OsString::new());
620-
621- // Trick, I saw on internet to point to the exe location..
622- let exe_path = key. get_value ( "DisplayIcon" ) . unwrap_or ( OsString :: new ( ) ) ;
623- if exe_path. is_empty ( ) {
624- return ;
625- }
626- // if there is something, it will be in the form of
627- // "C:\Program Files\Microsoft Office\Office16\WINWORD.EXE",0
628- let exe_path = exe_path. to_string_lossy ( ) . to_string ( ) ;
629- let exe = exe_path. split ( "," ) . next ( ) . unwrap ( ) . to_string ( ) ;
630-
631- if !display_name. is_empty ( ) {
632- apps. push ( App {
633- open_command : Function :: OpenApp ( exe) ,
634- name : display_name. clone ( ) . into_string ( ) . unwrap ( ) ,
635- name_lc : display_name. clone ( ) . into_string ( ) . unwrap ( ) . to_lowercase ( ) ,
636- icons : None ,
637- } )
638- }
639- } ) ;
640- } ) ;
641-
642- apps
643- }
0 commit comments