From b9399826e7e957f20c5eb9629f1e0885a47f2450 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sat, 6 Aug 2022 20:19:25 -0400 Subject: [PATCH] finish redoing Export to Application for macOS --- app/src/processing/app/Platform.java | 5 + .../processing/mode/java/ExportPrompt.java | 126 ++++-------------- java/src/processing/mode/java/JavaBuild.java | 2 +- todo.txt | 19 ++- 4 files changed, 47 insertions(+), 105 deletions(-) diff --git a/app/src/processing/app/Platform.java b/app/src/processing/app/Platform.java index 21d05ff4f..bd9fdc06e 100644 --- a/app/src/processing/app/Platform.java +++ b/app/src/processing/app/Platform.java @@ -260,6 +260,11 @@ public class Platform { } + static public String getPrettyName() { + return supportedVariants.get(getVariant()); + } + + // /** // * Map a platform constant to its name. // * @param which PConstants.WINDOWS, PConstants.MACOSX, PConstants.LINUX diff --git a/java/src/processing/mode/java/ExportPrompt.java b/java/src/processing/mode/java/ExportPrompt.java index 212a14370..83c4f2fc5 100644 --- a/java/src/processing/mode/java/ExportPrompt.java +++ b/java/src/processing/mode/java/ExportPrompt.java @@ -33,7 +33,6 @@ import processing.data.StringDict; import processing.data.StringList; import javax.swing.*; -import javax.swing.border.BevelBorder; import javax.swing.border.EmptyBorder; import javax.swing.border.TitledBorder; import java.awt.*; @@ -41,30 +40,19 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class ExportPrompt { - // Can't be .windows because that'll be stripped off as a per-platform pref + static final String MACOS_EXPORT_WIKI = + "https://github.com/processing/processing4/wiki/Exporting-Applications#macos"; static final String EXPORT_VARIANTS = "export.application.variants"; - /* - static final String EXPORT_PREFIX = "export.application.platform_"; - static final String EXPORT_MACOSX = EXPORT_PREFIX + "macosx"; - static final String EXPORT_WINDOWS = EXPORT_PREFIX + "windows"; - static final String EXPORT_LINUX = EXPORT_PREFIX + "linux"; - */ final JButton exportButton = new JButton(Language.text("prompt.export")); final JButton cancelButton = new JButton(Language.text("prompt.cancel")); - /* - final JCheckBox windowsButton = new JCheckBox("Windows"); - final JCheckBox macosButton = new JCheckBox("Mac OS X"); - final JCheckBox linuxButton = new JCheckBox("Linux"); - */ List variantButtons; final JavaEditor editor; @@ -94,16 +82,6 @@ public class ExportPrompt { button.setActionCommand(variant); button.addActionListener(e -> updateVariants()); variantButtons.add(button); - /* - final String variant = entry.key; - button.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - e.getActionCommand(); - toggleVariant(variant); - } - }); - */ } } @@ -120,26 +98,6 @@ public class ExportPrompt { } - /* - protected void toggleVariant(String variant) { - String pref = Preferences.get(EXPORT_VARIANTS); - StringList list = new StringList(pref.split(",")); - if (list.hasValue(variant)) { - list.removeValue(variant); - } else { - list.append(variant); - } - pref = list.join(","); - Preferences.set(EXPORT_VARIANTS, pref); - } - - - protected void updateExportButton() { - exportButton.setEnabled(anyExportButton()); - } - */ - - protected boolean anyExportButton() { for (JCheckBox button : variantButtons) { if (button.isSelected()) { @@ -192,11 +150,6 @@ public class ExportPrompt { int divWidth = platformPanel.getPreferredSize().width; -// Dimension labelDim = new Dimension(divWidth, label.getPreferredSize().height); -// label.setPreferredSize(labelDim); -// label.setMinimumSize(labelDim); -// label.setMaximumSize(labelDim); - final JCheckBox showStopButton = new JCheckBox(Language.text("export.options.show_stop_button")); showStopButton.setSelected(Preferences.getBoolean("export.application.stop")); showStopButton.addItemListener(e -> Preferences.setBoolean("export.application.stop", showStopButton.isSelected())); @@ -251,7 +204,7 @@ public class ExportPrompt { final boolean embed = Preferences.getBoolean("export.application.embed_java"); final String warning1 = - "
"; //"; + "
"; final String warning2a = "Embedding Java will make the " + platformName + " application " + "larger, but it will be far more likely to work. " + @@ -276,7 +229,8 @@ public class ExportPrompt { warningLabel.putClientProperty("FlatLaf.styleClass", "medium"); final JCheckBox embedJavaButton = - new JCheckBox(Language.interpolate("export.include_java", platformName)); + new JCheckBox(Language.interpolate("export.include_java", Platform.getPrettyName())); + //new JCheckBox(Language.interpolate("export.include_java", platformName)); embedJavaButton.setSelected(embed); embedJavaButton.addItemListener(e -> { boolean selected = embedJavaButton.isSelected(); @@ -302,40 +256,24 @@ public class ExportPrompt { signPanel.setLayout(new BoxLayout(signPanel, BoxLayout.Y_AXIS)); signPanel.setBorder(new TitledBorder(Language.text("export.code_signing"))); - // gatekeeper: http://support.apple.com/kb/ht5290 - // for developers: https://developer.apple.com/developer-id/ - final String APPLE_URL = "https://developer.apple.com/developer-id/"; String thePain = - //"" + - "In recent versions of macOS, Apple has introduced the \u201CGatekeeper\u201D system, " + - "which makes it more difficult to run applications like those exported from Processing. "; + "Applications on macOS must be \u201Csigned\u201D and \u201Cnotarized,\u201D " + + "or they will be reported as damaged or unsafe. "; - if (new File("/usr/bin/codesign_allocate").exists()) { + //if (false && new File("/usr/bin/codesign_allocate").exists()) { + if (JavaBuild.isXcodeInstalled()) { thePain += - "This application will be \u201Cself-signed\u201D which means that Finder may report that the " + - "application is from an \u201Cunidentified developer\u201D. If the application will not " + - "run, try right-clicking the app and selecting Open from the pop-up menu. Or you can visit " + - "System Preferences \u2192 Security & Privacy and select Allow apps downloaded from: anywhere. "; + "This application will be \u201Cself-signed\u201D which means that " + + "macOS may complain that is from an unidentified developer. " + + "If the application will not run, try right-clicking the app and " + + "selecting Open from the pop-up menu. " + + "More details at the Exporting Applications wiki page."; } else { thePain += - "Gatekeeper requires applications to be \u201Csigned\u201D, or they will be reported as damaged. " + - "To prevent this message, install Xcode (and the Command Line Tools) from the App Store. "; + "To sign the app, click here to begin " + + "installing the Command Line Tools from Apple. "; } - thePain += - "To avoid the messages entirely, manually code sign your app. " + - "For more information: " + APPLE_URL + ""; - // xattr -d com.apple.quarantine thesketch.app - - //signPanel.add(new JLabel(thePain)); - //JEditorPane area = new JEditorPane("text/html", thePain); - //JTextPane area = new JEditorPane("text/html", thePain); - -// JTextArea area = new JTextArea(thePain); -// area.setBackground(null); -// area.setFont(new Font("Dialog", Font.PLAIN, 10)); -// area.setLineWrap(true); -// area.setWrapStyleWord(true); // Are you f-king serious, Java API developers? // (Unless it's an HTML component, even with line wrap turned on, // getPreferredSize() will return the size for just a single line.) @@ -344,15 +282,23 @@ public class ExportPrompt { area.putClientProperty("FlatLaf.styleClass", "medium"); area.setBorder(new EmptyBorder(3, 13, 3, 13)); -// area.setPreferredSize(new Dimension(embedPanel.getPreferredSize().width, 100)); -// area.setPreferredSize(new Dimension(300, 200)); + // Using area.setPreferredSize() here doesn't help, + // but setting the div width in CSS above worked. signPanel.add(area); -// signPanel.add(Box.createHorizontalGlue()); signPanel.setAlignmentX(Component.LEFT_ALIGNMENT); area.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { - Platform.openURL("https://developer.apple.com/developer-id/"); + if (JavaBuild.isXcodeInstalled()) { + Platform.openURL(MACOS_EXPORT_WIKI); + + } else { + // Launch the process asynchronously + PApplet.exec("xcode-select", "--install"); + // Close the window so that we can rebuild it with different text + // once they've finished installing the Command Line Tools. + dialog.setVisible(false); + } } }); @@ -361,7 +307,6 @@ public class ExportPrompt { // - //String[] options = { Language.text("prompt.export"), Language.text("prompt.cancel") }; final JButton[] options = { exportButton, cancelButton }; final JOptionPane optionPane = new JOptionPane(panel, @@ -388,8 +333,6 @@ public class ExportPrompt { } }); dialog.pack(); -// System.out.println("after pack: " + panel.getPreferredSize()); -// dialog.setSize(optionPane.getPreferredSize()); dialog.setResizable(false); // Center the window in the middle of the editor @@ -446,17 +389,4 @@ public class ExportPrompt { chooser.hide(); } } - - -// protected void selectColor(String prefName) { -// Color color = Preferences.getColor(prefName); -// final ColorChooser chooser = new ColorChooser(JavaEditor.this, true, color, -// "Select", new ActionListener() { -// -// @Override -// public void actionPerformed(ActionEvent e) { -// Preferences.setColor(prefName, c.getColor()); -// } -// }); -// } } \ No newline at end of file diff --git a/java/src/processing/mode/java/JavaBuild.java b/java/src/processing/mode/java/JavaBuild.java index 65dad8cad..6a9dca880 100644 --- a/java/src/processing/mode/java/JavaBuild.java +++ b/java/src/processing/mode/java/JavaBuild.java @@ -1089,7 +1089,7 @@ public class JavaBuild { static protected boolean isXcodeInstalled() { if (xcodeInstalled == null) { - // Note that this is *not* an xcrun tool, because it's part of the OS. + // Note that xcode-select is *not* an xcrun tool: it's part of the OS. // pkgutil --file-info /usr/bin/xcode-select // https://stackoverflow.com/a/32752859/18247494 StringList stdout = new StringList(); diff --git a/todo.txt b/todo.txt index b809171c2..6b98fac82 100755 --- a/todo.txt +++ b/todo.txt @@ -18,6 +18,7 @@ X working on an updated welcome screen X fix usages of .array() method in PDE code X get code signing to work again on macOS for exported applications X absolutely floored that it was broken this long +X new docs added, window text redone docs X update theme instructions @@ -25,6 +26,8 @@ X https://github.com/processing/processing4/wiki/Themes X update the platforms page X https://github.com/processing/processing4/wiki/Supported-Platforms o rename to 'platforms'? +X rewrote Exporting Applications wiki page +X include more details about Gatekeeper et al temp X temp folders (particularly on Windows) @@ -270,10 +273,6 @@ _ also use id/ask for login to help understand community? _ tell users about JavaFX, Movie Maker install, changing themes _ final call on the About screen - -_ make sure mono font is coming from languages file when first setting editor pref -_ add wiki page for customization - new things + themes + naming @@ -287,6 +286,14 @@ old things + Examples window (Casey will pick 3-4) +_ make sure mono font is coming from languages file when first setting editor pref +_ naming selection not being set in prefs window +_ add wiki page for customization +_ "include Java for macOS" only relevant for current macOS platform +_ better to fix that, or make it possible to download both? + + + 4.0 / in the queue _ examples still coming from processing-docs repo _ https://github.com/processing/processing-examples @@ -301,8 +308,8 @@ _ update license info to state gplv2 not v3 _ run through that online license checker _ Export to Application on Apple Silicon is including a broken "Universal" appbundler _ need to lipo a new appbundler, or have it export one of the two files -_ “Array_Test.app” is damaged and can’t be opened. You should move it to the Trash. -_ https://github.com/processing/processing/issues/4214 (closed) +X “Array_Test.app” is damaged and can’t be opened. You should move it to the Trash. +X https://github.com/processing/processing/issues/4214 (closed) _ figure out if we can do anything with signing applications _ https://developer.apple.com/forums/thread/128166 _ https://developer.apple.com/forums/thread/701514#701514021