direct Main with arguments to CLI version
authorNiki Roo <niki@nikiroo.be>
Sun, 26 Apr 2020 12:37:15 +0000 (14:37 +0200)
committerNiki Roo <niki@nikiroo.be>
Sun, 26 Apr 2020 12:37:15 +0000 (14:37 +0200)
src/be/nikiroo/fanfix/Instance.java
src/be/nikiroo/fanfix_swing/Main.java
src/be/nikiroo/fanfix_swing/gui/book/BookPopup.java

index f48d05b7d4cd84994eeb7e5e238018e99317afbd..d0d1c84ab7643b65b34a91859a1b75ca59533091 100644 (file)
@@ -48,8 +48,19 @@ public class Instance {
        /**
         * Initialise the instance -- if already initialised, nothing will happen.
         * <p>
-        * Before calling this method, you may call {@link Bundles#setDirectory(String)}
-        * if wanted.
+        * Before calling this method, you may call
+        * {@link Bundles#setDirectory(String)} if wanted.
+        * <p>
+        * Note that this method will honour some environment variables, the 3 most
+        * important ones probably being:
+        * <ul>
+        * <li><tt>DEBUG</tt>: will enable DEBUG output if set to 1 (or Y or TRUE or
+        * ON, case insensitive)</li>
+        * <li><tt>CONFIG_DIR</tt>: will use this directory as configuration
+        * directory (supports $HOME notation, defaults to $HOME/.fanfix</li>
+        * <li><tt>BOOKS_DIR</tt>: will use this directory as library directory
+        * (supports $HOME notation, defaults to $HOME/Books</li>
+        * </ul>
         */
        static public void init() {
                init(false);
@@ -465,7 +476,6 @@ public class Instance {
                BasicLibrary lib = null;
 
                boolean useRemote = config.getBoolean(Config.REMOTE_LIBRARY_ENABLED, false);
-
                if (useRemote) {
                        String host = null;
                        int port = -1;
index cf83537f7aac5b392ba588a6c94dbcc927cd8063..91f65fce807adc315bec9a05d0353adaa08d3aa8 100644 (file)
@@ -12,40 +12,18 @@ import be.nikiroo.utils.ui.UIUtils;
 
 public class Main {
        public static void main(String[] args) {
-               UIUtils.setLookAndFeel();
-
-               final String forceLib = null;
-               // = "$HOME/Books/local";
-
-               if (forceLib == null) {
-                       Instance.init();
-               } else {
-                       Instance.init(new Instance() {
-                               private DataLoader cache;
-                               private BasicLibrary lib;
-
-                               @Override
-                               public DataLoader getCache() {
-                                       if (cache == null) {
-                                               cache = new DataLoader(getConfig()
-                                                               .getString(Config.NETWORK_USER_AGENT));
-                                       }
-
-                                       return cache;
-                               }
-
-                               @Override
-                               public BasicLibrary getLibrary() {
-                                       if (lib == null) {
-                                               lib = new LocalLibrary(getFile(forceLib), getConfig()) {
-                                               };
-                                       }
-
-                                       return lib;
-                               }
-                       });
+               // Defer to main application if parameters (we are only a UI)
+               // (though we could handle some of the parameters in the future,
+               // maybe importing via ImporterFrame? but that would require a
+               // unique instance of the UI to be usable...)
+               if (args != null && args.length > 0) {
+                       be.nikiroo.fanfix.Main.main(args);
+                       return;
                }
 
+               UIUtils.setLookAndFeel();
+               Instance.init();
+
                JFrame main = new MainFrame(true, true);
                main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                main.setVisible(true);
index d3f7e51bf91fc263b221aa54ef5f8f6fca673e8d..4fcaa56b6422313093c0c9145e086a52dafe0297 100644 (file)
@@ -45,6 +45,7 @@ public class BookPopup extends JPopupMenu {
                // not null
                public List<BookInfo> getSelected();
 
+               // visual only!
                public void setCached(BookInfo book, boolean cached);
 
                public BookInfo getUniqueSelected();