From 08bb2b614d3ba3e84cc4a3e23398c6839ff9bb5d Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Tue, 11 Jun 2019 02:17:58 +0100 Subject: [PATCH] load some gui props from a separate config file --- gui/griffon-app/lifecycle/Initialize.groovy | 52 +++++++++++++++++++-- gui/griffon-app/lifecycle/Ready.groovy | 31 +----------- 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/gui/griffon-app/lifecycle/Initialize.groovy b/gui/griffon-app/lifecycle/Initialize.groovy index 0b084e04..47c0f064 100644 --- a/gui/griffon-app/lifecycle/Initialize.groovy +++ b/gui/griffon-app/lifecycle/Initialize.groovy @@ -1,5 +1,6 @@ import griffon.core.GriffonApplication import groovy.util.logging.Log +import net.i2p.util.SystemVersion import org.codehaus.griffon.runtime.core.AbstractLifecycleHandler @@ -22,11 +23,54 @@ class Initialize extends AbstractLifecycleHandler { @Override void execute() { - if (isMacOSX()) { - lookAndFeel('nimbus') // otherwise the file chooser doesn't open??? - } else { - lookAndFeel('system', 'gtk') + log.info "Loading home dir" + def portableHome = System.getProperty("portable.home") + def home = portableHome == null ? + selectHome() : + portableHome + + home = new File(home) + if (!home.exists()) { + log.info("creating home dir $home") + home.mkdirs() } + + application.context.put("muwire-home", home.getAbsolutePath()) + + def guiPropsFile = new File(home, "gui.properties") + if (guiPropsFile.exists()) { + Properties props = new Properties() + guiPropsFile.withInputStream { props.load(it) } + log.info("settting user-specified lnf ${props['lnf']}") + lookAndFeel(props["lnf"]) + } else { + log.info "will try default lnfs" + if (isMacOSX()) { + lookAndFeel('nimbus') // otherwise the file chooser doesn't open??? + } else { + lookAndFeel('system', 'gtk') + } + } + } + + private static String selectHome() { + def home = new File(System.properties["user.home"]) + def defaultHome = new File(home, ".MuWire") + if (defaultHome.exists()) + return defaultHome.getAbsolutePath() + if (SystemVersion.isMac()) { + def library = new File(home, "Library") + def appSupport = new File(library, "Application Support") + def muwire = new File(appSupport,"MuWire") + return muwire.getAbsolutePath() + } + if (SystemVersion.isWindows()) { + def appData = new File(home,"AppData") + def roaming = new File(appData, "Roaming") + def muwire = new File(roaming, "MuWire") + return muwire.getAbsolutePath() + } + defaultHome.getAbsolutePath() } } diff --git a/gui/griffon-app/lifecycle/Ready.groovy b/gui/griffon-app/lifecycle/Ready.groovy index e90c8ab2..7f8419f5 100644 --- a/gui/griffon-app/lifecycle/Ready.groovy +++ b/gui/griffon-app/lifecycle/Ready.groovy @@ -34,17 +34,8 @@ class Ready extends AbstractLifecycleHandler { @Override void execute() { log.info "starting core services" - def portableHome = System.getProperty("portable.home") - def home = portableHome == null ? - selectHome() : - portableHome - - home = new File(home) - if (!home.exists()) { - log.info("creating home dir $home") - home.mkdirs() - } + def home = new File(application.getContext().getAsString("muwire-home")) def props = new Properties() def propsFile = new File(home, "MuWire.properties") if (propsFile.exists()) { @@ -121,25 +112,5 @@ class Ready extends AbstractLifecycleHandler { core.eventBus.publish(new UILoadedEvent()) } - - private static String selectHome() { - def home = new File(System.properties["user.home"]) - def defaultHome = new File(home, ".MuWire") - if (defaultHome.exists()) - return defaultHome.getAbsolutePath() - if (SystemVersion.isMac()) { - def library = new File(home, "Library") - def appSupport = new File(library, "Application Support") - def muwire = new File(appSupport,"MuWire") - return muwire.getAbsolutePath() - } - if (SystemVersion.isWindows()) { - def appData = new File(home,"AppData") - def roaming = new File(appData, "Roaming") - def muwire = new File(roaming, "MuWire") - return muwire.getAbsolutePath() - } - defaultHome.getAbsolutePath() - } }