File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -116,8 +116,47 @@ impl App {
116
116
}
117
117
118
118
fn detect_terminal ( ) -> ( PathBuf , & ' static str ) {
119
+ use freedesktop_desktop_entry:: DesktopEntry ;
119
120
use std:: fs:: read_link;
120
121
122
+ let terminal_apps: Vec < _ > =
123
+ freedesktop_desktop_entry:: Iter :: new ( freedesktop_desktop_entry:: default_paths ( ) )
124
+ . filter_map ( |path| {
125
+ std:: fs:: read_to_string ( & path) . ok ( ) . and_then ( |input| {
126
+ DesktopEntry :: decode ( & path, & input) . ok ( ) . and_then ( |de| {
127
+ if de. no_display ( )
128
+ || de
129
+ . categories ( )
130
+ . map ( |c| c. split_terminator ( ';' ) . all ( |c| c != "TerminalEmulator" ) )
131
+ . unwrap_or ( true )
132
+ || de. exec ( ) . is_none ( )
133
+ {
134
+ return None ;
135
+ }
136
+
137
+ Some ( ( de. id ( ) . to_owned ( ) , de. exec ( ) . unwrap ( ) . to_owned ( ) ) )
138
+ } )
139
+ } )
140
+ } )
141
+ . collect ( ) ;
142
+
143
+ for id in [ "com.system76.CosmicTerm" ] {
144
+ for ( terminal_id, exec) in & terminal_apps {
145
+ if terminal_id. as_str ( ) == id {
146
+ return ( PathBuf :: from ( exec) , "-e" ) ;
147
+ }
148
+ }
149
+ }
150
+
151
+ if let Some ( ( id, exec) ) = terminal_apps. first ( ) {
152
+ let arg = if id == "org.gnome.Terminal" {
153
+ "--"
154
+ } else {
155
+ "-e"
156
+ } ;
157
+ return ( PathBuf :: from ( exec) , arg) ;
158
+ }
159
+
121
160
const SYMLINK : & str = "/usr/bin/x-terminal-emulator" ;
122
161
123
162
if let Ok ( found) = read_link ( SYMLINK ) {
You can’t perform that action at this time.
0 commit comments