@@ -13,6 +13,8 @@ namespace SourceGit.Native
1313 [ SupportedOSPlatform ( "linux" ) ]
1414 internal class Linux : OS . IBackend
1515 {
16+ private static readonly string LOCAL_APP_DATA_DIR = Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) ;
17+
1618 public void SetupApp ( AppBuilder builder )
1719 {
1820 builder . With ( new X11PlatformOptions ( ) { EnableIme = true } ) ;
@@ -48,16 +50,16 @@ public string FindTerminal(Models.ShellOrTerminal shell)
4850
4951 public List < Models . ExternalTool > FindExternalTools ( )
5052 {
51- var localAppDataDir = Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) ;
5253 var finder = new Models . ExternalToolsFinder ( ) ;
53- finder . VSCode ( ( ) => FindExecutable ( "code" ) ) ;
54- finder . VSCodeInsiders ( ( ) => FindExecutable ( "code-insiders" ) ) ;
55- finder . VSCodium ( ( ) => FindExecutable ( "codium" ) ) ;
54+ finder . VSCode ( ( ) => FindExecutable ( "code" , "com.visualstudio.code" ) ) ;
55+ finder . VSCodeInsiders ( ( ) => FindExecutable ( "code-insiders" , "com.vscodium.codium-insiders" ) ) ;
56+ finder . VSCodium ( ( ) => FindExecutable ( "codium" , "com.vscodium.codium" ) ) ;
5657 finder . Cursor ( ( ) => FindExecutable ( "cursor" ) ) ;
57- finder . Fleet ( ( ) => FindJetBrainsFleet ( localAppDataDir ) ) ;
58- finder . FindJetBrainsFromToolbox ( ( ) => Path . Combine ( localAppDataDir , "JetBrains/Toolbox" ) ) ;
59- finder . SublimeText ( ( ) => FindExecutable ( "subl" ) ) ;
60- finder . Zed ( ( ) => FindExecutable ( "zeditor" ) ) ;
58+ finder . Fleet ( FindJetBrainsFleet ) ;
59+ finder . FindJetBrainsFromToolbox ( ( ) => Path . Combine ( LOCAL_APP_DATA_DIR , "JetBrains/Toolbox" ) ) ;
60+ FindJetBrainsFromFlatpak ( finder ) ;
61+ finder . SublimeText ( ( ) => FindExecutable ( "subl" , "com.sublimetext.three" ) ) ;
62+ finder . Zed ( ( ) => FindExecutable ( "zeditor" , "dev.zed.Zed" ) ) ;
6163 return finder . Tools ;
6264 }
6365
@@ -119,7 +121,7 @@ public void OpenWithDefaultEditor(string file)
119121 }
120122 }
121123
122- private string FindExecutable ( string filename )
124+ private static string FindExecutable ( string filename , string flatpakAppId = null )
123125 {
124126 var pathVariable = Environment . GetEnvironmentVariable ( "PATH" ) ?? string . Empty ;
125127 var paths = pathVariable . Split ( Path . PathSeparator , StringSplitOptions . RemoveEmptyEntries ) ;
@@ -130,13 +132,51 @@ private string FindExecutable(string filename)
130132 return test ;
131133 }
132134
135+ if ( flatpakAppId != null )
136+ {
137+ foreach ( var path in new [ ] { "/var/lib" , LOCAL_APP_DATA_DIR } )
138+ {
139+ var test = Path . Combine ( path , "flatpak/exports/bin" , flatpakAppId ) ;
140+ if ( File . Exists ( test ) )
141+ return test ;
142+ }
143+ }
144+
133145 return string . Empty ;
134146 }
135147
136- private string FindJetBrainsFleet ( string localAppDataDir )
148+ private static string FindJetBrainsFleet ( )
137149 {
138- var path = Path . Combine ( localAppDataDir , "JetBrains/Toolbox/apps/fleet/bin/Fleet" ) ;
150+ var path = Path . Combine ( LOCAL_APP_DATA_DIR , "JetBrains/Toolbox/apps/fleet/bin/Fleet" ) ;
139151 return File . Exists ( path ) ? path : FindExecutable ( "fleet" ) ;
140152 }
153+
154+ private static void FindJetBrainsFromFlatpak ( Models . ExternalToolsFinder finder )
155+ {
156+ foreach ( var basePath in new [ ] { "/var/lib" , LOCAL_APP_DATA_DIR } )
157+ {
158+ var binPath = Path . Combine ( basePath , "flatpak/exports/bin" ) ;
159+ if ( Directory . Exists ( binPath ) )
160+ {
161+ foreach ( var file in Directory . GetFiles ( binPath , "com.jetbrains.*" ) )
162+ {
163+ var fileName = Path . GetFileName ( file ) ;
164+ var appName = fileName [ 14 ..] . Replace ( "-" , " " ) ;
165+ var icon = new string ( Array . FindAll ( fileName . ToCharArray ( ) , char . IsUpper ) ) ;
166+ if ( icon . Length > 2 )
167+ icon = icon [ ..2 ] ;
168+ icon = icon switch
169+ {
170+ "DG" => "DB" , // DataGrip
171+ "GL" => "GO" , // GoLand
172+ "IJ" => "JB" , // IntelliJ
173+ "R" => "RD" , // Rider
174+ _ => icon
175+ } ;
176+ finder . Tools . Add ( new Models . ExternalTool ( appName , "JetBrains/" + icon , file ) ) ;
177+ }
178+ }
179+ }
180+ }
141181 }
142182}
0 commit comments