correct startup sequence, add listeners for allFilesLoadedEvent

pull/24/head
Zlatin Balevsky 2019-10-25 06:01:16 +01:00
parent b30e552498
commit 70913ea8fb
2 changed files with 35 additions and 2 deletions

View File

@ -29,6 +29,7 @@ import com.googlecode.lanterna.terminal.Terminal
import com.muwire.core.Core
import com.muwire.core.MuWireSettings
import com.muwire.core.UILoadedEvent
import com.muwire.core.files.AllFilesLoadedEvent
class CliLanterna {
private static final String MW_VERSION = "0.5.3"
@ -130,7 +131,6 @@ class CliLanterna {
Thread connector = new Thread({
try {
core = new Core(props, home, MW_VERSION)
core.startServices()
} finally {
latch.countDown()
}
@ -155,9 +155,25 @@ class CliLanterna {
}
window = new MainWindowView("MuWire "+MW_VERSION, core, textGUI, screen)
core.startServices()
core.eventBus.publish(new UILoadedEvent())
textGUI.addWindowAndWait(window)
CountDownLatch latch = new CountDownLatch(1)
Thread stopper = new Thread({
core.shutdown()
latch.countDown()
} as Runnable)
WaitingDialog waitingForShutdown = new WaitingDialog("MuWire is shutting down","Please wait")
waitingForShutdown.showDialog(textGUI, false)
stopper.start()
while(latch.getCount() > 0) {
textGUI.updateScreen()
Thread.sleep(10)
}
waitingForShutdown.close()
screen.stopScreen()
System.exit(0)
}

View File

@ -4,9 +4,12 @@ import com.googlecode.lanterna.gui2.TextGUIThread
import com.googlecode.lanterna.gui2.table.TableModel
import com.muwire.core.Core
import com.muwire.core.SharedFile
import com.muwire.core.files.AllFilesLoadedEvent
import com.muwire.core.files.FileHashedEvent
import com.muwire.core.files.FileLoadedEvent
import com.muwire.core.files.FileSharedEvent
import com.muwire.core.files.FileUnsharedEvent
import com.muwire.core.trust.TrustSubscriptionEvent
import net.i2p.data.DataHelper
@ -23,6 +26,7 @@ class FilesModel {
core.eventBus.register(FileLoadedEvent.class, this)
core.eventBus.register(FileUnsharedEvent.class, this)
core.eventBus.register(FileHashedEvent.class, this)
core.eventBus.register(AllFilesLoadedEvent.class, this)
Runnable refreshModel = {refreshModel()}
Timer timer = new Timer(true)
@ -32,6 +36,19 @@ class FilesModel {
}
void onAllFilesLoadedEvent(AllFilesLoadedEvent e) {
def eventBus = core.eventBus
guiThread.invokeLater {
core.muOptions.watchedDirectories.each {
eventBus.publish(new FileSharedEvent(file : new File(it)))
}
// TODO: move this to the trust model class
core.muOptions.trustSubscriptions.each {
eventBus.publish(new TrustSubscriptionEvent(persona : it, subscribe : true))
}
}
}
void onFileLoadedEvent(FileLoadedEvent e) {
guiThread.invokeLater {
sharedFiles.add(e.loadedFile)