Files
muwire/gui/griffon-app/lifecycle/Ready.groovy

59 lines
1.6 KiB
Groovy
Raw Normal View History

2019-05-29 18:22:48 +01:00
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
2019-05-29 19:05:19 +01:00
import java.beans.PropertyChangeEvent
2019-05-29 18:22:48 +01:00
@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)
2019-05-29 19:05:19 +01:00
application.getPropertyChangeListeners("core").each {
it.propertyChange(new PropertyChangeEvent(this, "core", null, core))
}
2019-05-29 18:22:48 +01:00
}
}