load some gui props from a separate config file

This commit is contained in:
Zlatin Balevsky
2019-06-11 02:17:58 +01:00
parent d0e5d0ce8a
commit 08bb2b614d
2 changed files with 49 additions and 34 deletions

View File

@@ -1,5 +1,6 @@
import griffon.core.GriffonApplication import griffon.core.GriffonApplication
import groovy.util.logging.Log import groovy.util.logging.Log
import net.i2p.util.SystemVersion
import org.codehaus.griffon.runtime.core.AbstractLifecycleHandler import org.codehaus.griffon.runtime.core.AbstractLifecycleHandler
@@ -22,11 +23,54 @@ class Initialize extends AbstractLifecycleHandler {
@Override @Override
void execute() { void execute() {
if (isMacOSX()) { log.info "Loading home dir"
lookAndFeel('nimbus') // otherwise the file chooser doesn't open??? def portableHome = System.getProperty("portable.home")
} else { def home = portableHome == null ?
lookAndFeel('system', 'gtk') 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()
} }
} }

View File

@@ -34,17 +34,8 @@ class Ready extends AbstractLifecycleHandler {
@Override @Override
void execute() { void execute() {
log.info "starting core services" 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 props = new Properties()
def propsFile = new File(home, "MuWire.properties") def propsFile = new File(home, "MuWire.properties")
if (propsFile.exists()) { if (propsFile.exists()) {
@@ -121,25 +112,5 @@ class Ready extends AbstractLifecycleHandler {
core.eventBus.publish(new UILoadedEvent()) 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()
}
} }