Merge branch 'develop' into bug/JAL-1988_JAL-3772_improved_quit_handling
authorBen Soares <b.soares@dundee.ac.uk>
Thu, 27 Oct 2022 15:20:14 +0000 (16:20 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Thu, 27 Oct 2022 15:20:14 +0000 (16:20 +0100)
1  2 
src/jalview/bin/Jalview.java

@@@ -73,8 -73,6 +73,8 @@@ import jalview.io.HtmlSvgOutput
  import jalview.io.IdentifyFile;
  import jalview.io.NewickFile;
  import jalview.io.gff.SequenceOntologyFactory;
 +import jalview.jbgui.QuitHandler;
 +import jalview.jbgui.QuitHandler.QResponse;
  import jalview.schemes.ColourSchemeI;
  import jalview.schemes.ColourSchemeProperty;
  import jalview.util.ChannelProperties;
@@@ -273,28 -271,6 +273,28 @@@ public class Jalvie
      if (!Platform.isJS())
      {
        System.setSecurityManager(null);
 +
 +      Runtime.getRuntime().addShutdownHook(new Thread()
 +      {
 +        public void run()
 +        {
 +          Console.debug("Running shutdown hook");
 +          if (QuitHandler.gotQuitResponse() == QResponse.CANCEL_QUIT)
 +          {
 +            // Got to here by a SIGTERM signal.
 +            // Note we will not actually cancel the quit from here -- it's too
 +            // late -- but we can wait for saving files.
 +            Console.debug("Checking for saving files");
 +            QuitHandler.getQuitResponse(false);
 +          }
 +          else
 +          {
 +            Console.debug("Nothing more to do");
 +          }
 +          Console.debug("Exiting, bye!");
 +          // shutdownHook cannot be cancelled, JVM will now halt
 +        }
 +      });
      }
  
      System.out
      System.out.println(System.getProperty("os.arch") + " "
              + System.getProperty("os.name") + " "
              + System.getProperty("os.version"));
 +
      String val = System.getProperty("sys.install4jVersion");
      if (val != null)
      {
      Cache.loadBuildProperties(true);
  
      ArgsParser aparser = new ArgsParser(args);
 +
      boolean headless = false;
  
      String usrPropsFile = aparser.getValue("props");
 -    Cache.loadProperties(usrPropsFile); // must do this before
 +    Cache.loadProperties(usrPropsFile); // must do this
 +                                        // before
      if (usrPropsFile != null)
      {
        System.out.println(
      try
      {
        Console.initLogger();
 -    } catch (NoClassDefFoundError error)
 +    } catch (
 +
 +    NoClassDefFoundError error)
      {
        error.printStackTrace();
        System.out.println("\nEssential logging libraries not found."
      }
  
      String file = null, data = null;
 +
      FileFormatI format = null;
 +
      DataSourceType protocol = null;
 +
      FileLoader fileLoader = new FileLoader(!headless);
  
      String groovyscript = null; // script to execute after all loading is
        System.out.println("No files to open!");
        System.exit(1);
      }
 +
      long progress = -1;
      // Finally, deal with the remaining input data.
      if (file != null)
          }
        }
      }
 +
      AlignFrame startUpAlframe = null;
      // We'll only open the default file if the desktop is visible.
      // And the user
      System.setProperty("com.apple.mrj.application.apple.menu.about.name",
              ChannelProperties.getProperty("app_name"));
      System.setProperty("apple.laf.useScreenMenuBar", "true");
+     /*
+      * broken native LAFs on (ARM?) macbooks
      set = setQuaquaLookAndFeel();
      if ((!set) || !UIManager.getLookAndFeel().getClass().toString()
              .toLowerCase(Locale.ROOT).contains("quaqua"))
      {
        set = setVaquaLookAndFeel();
      }
+      */
+     set = setFlatLookAndFeel();
      return set;
    }
  
    }
  
    /**
 -   * Quit method delegates to Desktop.quit - unless running in headless mode
 -   * when it just ends the JVM
 +   * jalview.bin.Jalview.quit() will just run the non-GUI shutdownHook and exit
     */
    public void quit()
    {
 -    if (desktop != null)
 -    {
 -      desktop.quit();
 -    }
 -    else
 -    {
 -      System.exit(0);
 -    }
 +    // System.exit will run the shutdownHook first
 +    System.exit(0);
    }
  
    public static AlignFrame getCurrentAlignFrame()