diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index 2dc61142..87bb198e 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -64,7 +64,7 @@ public class Core { private final ConnectionEstablisher connectionEstablisher private final HasherService hasherService - public Core(MuWireSettings props) { + public Core(MuWireSettings props, File home) { log.info "Initializing I2P context" I2PAppContext.getGlobalContext().logManager() I2PAppContext.getGlobalContext()._logManager = new MuWireLogManager() @@ -221,7 +221,7 @@ public class Core { } } - Core core = new Core(props) + Core core = new Core(props, home) core.startServices() // ... at the end, sleep or execute script diff --git a/gui/griffon-app/lifecycle/Initialize.groovy b/gui/griffon-app/lifecycle/Initialize.groovy new file mode 100644 index 00000000..11e616cf --- /dev/null +++ b/gui/griffon-app/lifecycle/Initialize.groovy @@ -0,0 +1,27 @@ +import griffon.core.GriffonApplication +import groovy.util.logging.Log + +import org.codehaus.griffon.runtime.core.AbstractLifecycleHandler + +import com.muwire.core.Core +import com.muwire.core.MuWireSettings + +import javax.annotation.Nonnull +import javax.inject.Inject + +import static griffon.util.GriffonApplicationUtils.isMacOSX +import static groovy.swing.SwingBuilder.lookAndFeel + +@Log +class Initialize extends AbstractLifecycleHandler { + @Inject + Initialize(@Nonnull GriffonApplication application) { + super(application) + } + + @Override + void execute() { + lookAndFeel((isMacOSX ? 'system' : 'nimbus'), 'gtk', ['metal', [boldFonts: false]]) + } +} + diff --git a/gui/griffon-app/lifecycle/Ready.groovy b/gui/griffon-app/lifecycle/Ready.groovy new file mode 100644 index 00000000..70180c00 --- /dev/null +++ b/gui/griffon-app/lifecycle/Ready.groovy @@ -0,0 +1,53 @@ +import griffon.core.GriffonApplication +import groovy.util.logging.Log + +import org.codehaus.griffon.runtime.core.AbstractLifecycleHandler + +import com.muwire.core.Core +import com.muwire.core.MuWireSettings + +import javax.annotation.Nonnull +import javax.inject.Inject + +import static griffon.util.GriffonApplicationUtils.isMacOSX +import static groovy.swing.SwingBuilder.lookAndFeel + +@Log +class Ready extends AbstractLifecycleHandler { + @Inject + Ready(@Nonnull GriffonApplication application) { + super(application) + } + + @Override + void execute() { + log.info "starting core services" + def home = System.getProperty("user.home") + File.separator + ".MuWire" + home = new File(home) + if (!home.exists()) { + log.info("creating home dir") + home.mkdir() + } + + def props = new Properties() + def propsFile = new File(home, "MuWire.properties") + if (propsFile.exists()) { + log.info("loading existing props file") + propsFile.withInputStream { + props.load(it) + } + props = new MuWireSettings(props) + } else { + log.info("creating default properties") + props = new MuWireSettings() + propsFile.withOutputStream { + props.write(it) + } + } + + Core core = new Core(props, home) + core.startServices() + application.context.put("core",core) + } +} +