1
1
/*
2
- * Copyright (c) 2019, 2022 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2019, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -63,9 +63,10 @@ final class DesktopIntegration extends ShellCustomAction {
63
63
private static final String COMMANDS_INSTALL = "DESKTOP_COMMANDS_INSTALL" ;
64
64
private static final String COMMANDS_UNINSTALL = "DESKTOP_COMMANDS_UNINSTALL" ;
65
65
private static final String SCRIPTS = "DESKTOP_SCRIPTS" ;
66
+ private static final String COMMON_SCRIPTS = "COMMON_SCRIPTS" ;
66
67
67
68
private static final List <String > REPLACEMENT_STRING_IDS = List .of (
68
- COMMANDS_INSTALL , COMMANDS_UNINSTALL , SCRIPTS );
69
+ COMMANDS_INSTALL , COMMANDS_UNINSTALL , SCRIPTS , COMMON_SCRIPTS );
69
70
70
71
private DesktopIntegration (PlatformPackage thePackage ,
71
72
Map <String , ? super Object > params ,
@@ -229,8 +230,6 @@ protected Map<String, String> createImpl() throws IOException {
229
230
shellCommands .applyTo (data );
230
231
}
231
232
232
- boolean needCleanupScripts = !associations .isEmpty ();
233
-
234
233
// Take care of additional launchers if there are any.
235
234
// Process every additional launcher as the main application launcher.
236
235
// Collect shell commands to install/uninstall integration with desktop
@@ -241,10 +240,6 @@ protected Map<String, String> createImpl() throws IOException {
241
240
List <String > uninstallShellCmds = new ArrayList <>(Arrays .asList (
242
241
data .get (COMMANDS_UNINSTALL )));
243
242
for (var integration : nestedIntegrations ) {
244
- if (!integration .associations .isEmpty ()) {
245
- needCleanupScripts = true ;
246
- }
247
-
248
243
Map <String , String > launcherData = integration .create ();
249
244
250
245
installShellCmds .add (launcherData .get (COMMANDS_INSTALL ));
@@ -254,10 +249,8 @@ protected Map<String, String> createImpl() throws IOException {
254
249
data .put (COMMANDS_INSTALL , stringifyShellCommands (installShellCmds ));
255
250
data .put (COMMANDS_UNINSTALL , stringifyShellCommands (uninstallShellCmds ));
256
251
257
- if (needCleanupScripts ) {
258
- // Pull in desktop_utils.sh scrips library.
259
- data .put (SCRIPTS , stringifyTextFile ("desktop_utils.sh" ));
260
- }
252
+ data .put (COMMON_SCRIPTS , stringifyTextFile ("common_utils.sh" ));
253
+ data .put (SCRIPTS , stringifyTextFile ("desktop_utils.sh" ));
261
254
262
255
return data ;
263
256
}
@@ -295,16 +288,20 @@ private class ShellCommands {
295
288
296
289
registerDesktopFileCmd = String .join (" " , "xdg-desktop-menu" ,
297
290
"install" , desktopFile .installPath ().toString ());
298
- unregisterDesktopFileCmd = String .join (" " , "xdg-desktop-menu" ,
291
+ unregisterDesktopFileCmd = String .join (" " ,
292
+ "do_if_file_belongs_to_single_package" , desktopFile .
293
+ installPath ().toString (), "xdg-desktop-menu" ,
299
294
"uninstall" , desktopFile .installPath ().toString ());
300
295
}
301
296
302
297
void setFileAssociations () {
303
298
registerFileAssociationsCmd = String .join (" " , "xdg-mime" ,
304
299
"install" ,
305
300
mimeInfoFile .installPath ().toString ());
306
- unregisterFileAssociationsCmd = String .join (" " , "xdg-mime" ,
307
- "uninstall" , mimeInfoFile .installPath ().toString ());
301
+ unregisterFileAssociationsCmd = String .join (" " ,
302
+ "do_if_file_belongs_to_single_package" , mimeInfoFile .
303
+ installPath ().toString (), "xdg-mime" , "uninstall" ,
304
+ mimeInfoFile .installPath ().toString ());
308
305
309
306
//
310
307
// Add manual cleanup of system files to get rid of
@@ -320,26 +317,26 @@ void setFileAssociations() {
320
317
// of non-existing desktop file.
321
318
//
322
319
String cleanUpCommand = String .join (" " ,
323
- "uninstall_default_mime_handler" ,
324
- desktopFile .installPath ().getFileName ().toString (),
325
- String .join (" " , getMimeTypeNamesFromFileAssociations ()));
320
+ "do_if_file_belongs_to_single_package" , desktopFile .
321
+ installPath ().toString (),
322
+ "desktop_uninstall_default_mime_handler" , desktopFile .
323
+ installPath ().getFileName ().toString (), String .join (
324
+ " " , getMimeTypeNamesFromFileAssociations ()));
326
325
327
326
unregisterFileAssociationsCmd = stringifyShellCommands (
328
327
unregisterFileAssociationsCmd , cleanUpCommand );
329
328
}
330
329
331
- void addIcon (String mimeType , Path iconFile ) {
332
- addIcon (mimeType , iconFile , getSquareSizeOfImage (iconFile .toFile ()));
333
- }
334
-
335
330
void addIcon (String mimeType , Path iconFile , int imgSize ) {
336
331
imgSize = normalizeIconSize (imgSize );
337
332
final String dashMime = mimeType .replace ('/' , '-' );
338
333
registerIconCmds .add (String .join (" " , "xdg-icon-resource" ,
339
334
"install" , "--context" , "mimetypes" , "--size" ,
340
335
Integer .toString (imgSize ), iconFile .toString (), dashMime ));
341
- unregisterIconCmds .add (String .join (" " , "xdg-icon-resource" ,
342
- "uninstall" , dashMime , "--size" , Integer .toString (imgSize )));
336
+ unregisterIconCmds .add (String .join (" " ,
337
+ "do_if_file_belongs_to_single_package" , iconFile .toString (),
338
+ "xdg-icon-resource" , "uninstall" , dashMime , "--size" ,
339
+ Integer .toString (imgSize )));
343
340
}
344
341
345
342
void applyTo (Map <String , String > data ) {
0 commit comments