From 70913ea8fb7d3350e23c98f5f07810c68986b0f1 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 25 Oct 2019 06:01:16 +0100 Subject: [PATCH] correct startup sequence, add listeners for allFilesLoadedEvent --- .../com/muwire/clilanterna/CliLanterna.groovy | 20 +++++++++++++++++-- .../com/muwire/clilanterna/FilesModel.groovy | 17 ++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/CliLanterna.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/CliLanterna.groovy index 683f0457..2dfd896e 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/CliLanterna.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/CliLanterna.groovy @@ -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) - core.shutdown() + + 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) } diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/FilesModel.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/FilesModel.groovy index eadc098e..4e5333ca 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/FilesModel.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/FilesModel.groovy @@ -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)