@@ -13,6 +13,8 @@ namespace SourceGit.Native
13
13
[ SupportedOSPlatform ( "linux" ) ]
14
14
internal class Linux : OS . IBackend
15
15
{
16
+ private static readonly string LOCAL_APP_DATA_DIR = Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) ;
17
+
16
18
public void SetupApp ( AppBuilder builder )
17
19
{
18
20
builder . With ( new X11PlatformOptions ( ) { EnableIme = true } ) ;
@@ -48,16 +50,16 @@ public string FindTerminal(Models.ShellOrTerminal shell)
48
50
49
51
public List < Models . ExternalTool > FindExternalTools ( )
50
52
{
51
- var localAppDataDir = Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) ;
52
53
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" ) ) ;
56
57
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" ) ) ;
61
63
return finder . Tools ;
62
64
}
63
65
@@ -119,7 +121,7 @@ public void OpenWithDefaultEditor(string file)
119
121
}
120
122
}
121
123
122
- private string FindExecutable ( string filename )
124
+ private static string FindExecutable ( string filename , string flatpakAppId = null )
123
125
{
124
126
var pathVariable = Environment . GetEnvironmentVariable ( "PATH" ) ?? string . Empty ;
125
127
var paths = pathVariable . Split ( Path . PathSeparator , StringSplitOptions . RemoveEmptyEntries ) ;
@@ -130,13 +132,51 @@ private string FindExecutable(string filename)
130
132
return test ;
131
133
}
132
134
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
+
133
145
return string . Empty ;
134
146
}
135
147
136
- private string FindJetBrainsFleet ( string localAppDataDir )
148
+ private static string FindJetBrainsFleet ( )
137
149
{
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" ) ;
139
151
return File . Exists ( path ) ? path : FindExecutable ( "fleet" ) ;
140
152
}
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
+ }
141
181
}
142
182
}
0 commit comments