Add update notification window

This commit is contained in:
Zlatin Balevsky
2019-10-31 20:51:09 +00:00
parent f7e28e04f6
commit 2429bbf59e
8 changed files with 125 additions and 13 deletions

View File

@@ -7,4 +7,5 @@ class UpdateAvailableEvent extends Event {
String version String version
String signer String signer
String infoHash String infoHash
String text
} }

View File

@@ -40,6 +40,8 @@ class UpdateClient {
private volatile InfoHash updateInfoHash private volatile InfoHash updateInfoHash
private volatile String version, signer private volatile String version, signer
private volatile boolean updateDownloading private volatile boolean updateDownloading
private volatile String text
UpdateClient(EventBus eventBus, I2PSession session, String myVersion, MuWireSettings settings, FileManager fileManager, Persona me) { UpdateClient(EventBus eventBus, I2PSession session, String myVersion, MuWireSettings settings, FileManager fileManager, Persona me) {
this.eventBus = eventBus this.eventBus = eventBus
@@ -75,7 +77,7 @@ class UpdateClient {
if (e.downloadedFile.infoHash != updateInfoHash) if (e.downloadedFile.infoHash != updateInfoHash)
return return
updateDownloading = false updateDownloading = false
eventBus.publish(new UpdateDownloadedEvent(version : version, signer : signer)) eventBus.publish(new UpdateDownloadedEvent(version : version, signer : signer, text : text))
} }
private void checkUpdate() { private void checkUpdate() {
@@ -147,15 +149,16 @@ class UpdateClient {
} else } else
infoHash = payload[settings.updateType] infoHash = payload[settings.updateType]
text = payload.text
if (!settings.autoDownloadUpdate) { if (!settings.autoDownloadUpdate) {
log.info("new version $payload.version available, publishing event") log.info("new version $payload.version available, publishing event")
eventBus.publish(new UpdateAvailableEvent(version : payload.version, signer : payload.signer, infoHash : infoHash)) eventBus.publish(new UpdateAvailableEvent(version : payload.version, signer : payload.signer, infoHash : infoHash, text : text))
} else { } else {
log.info("new version $payload.version available") log.info("new version $payload.version available")
updateInfoHash = new InfoHash(Base64.decode(infoHash)) updateInfoHash = new InfoHash(Base64.decode(infoHash))
if (fileManager.rootToFiles.containsKey(updateInfoHash)) if (fileManager.rootToFiles.containsKey(updateInfoHash))
eventBus.publish(new UpdateDownloadedEvent(version : payload.version, signer : payload.signer)) eventBus.publish(new UpdateDownloadedEvent(version : payload.version, signer : payload.signer, text : text))
else { else {
updateDownloading = false updateDownloading = false
version = payload.version version = payload.version

View File

@@ -5,4 +5,5 @@ import com.muwire.core.Event
class UpdateDownloadedEvent extends Event { class UpdateDownloadedEvent extends Event {
String version String version
String signer String signer
String text
} }

View File

@@ -76,4 +76,9 @@ mvcGroups {
view = 'com.muwire.gui.CloseWarningView' view = 'com.muwire.gui.CloseWarningView'
controller = 'com.muwire.gui.CloseWarningController' controller = 'com.muwire.gui.CloseWarningController'
} }
'update' {
model = 'com.muwire.gui.UpdateModel'
view = 'com.muwire.gui.UpdateView'
controller = 'com.muwire.gui.UpdateController'
}
} }

View File

@@ -0,0 +1,27 @@
package com.muwire.gui
import griffon.core.artifact.GriffonController
import griffon.core.controller.ControllerAction
import griffon.inject.MVCMember
import griffon.metadata.ArtifactProviderFor
import javax.annotation.Nonnull
@ArtifactProviderFor(GriffonController)
class UpdateController {
@MVCMember @Nonnull
UpdateView view
@MVCMember @Nonnull
UpdateModel model
@ControllerAction
void close() {
view.dialog.setVisible(false)
mvcGroup.destroy()
}
@ControllerAction
void search() {
mvcGroup.parentGroup.controller.search(model.available.infoHash, "MuWire update")
close()
}
}

View File

@@ -1,3 +1,4 @@
package com.muwire.gui package com.muwire.gui
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
@@ -264,8 +265,10 @@ class MainFrameModel {
void onUpdateDownloadedEvent(UpdateDownloadedEvent e) { void onUpdateDownloadedEvent(UpdateDownloadedEvent e) {
runInsideUIAsync { runInsideUIAsync {
JOptionPane.showMessageDialog(null, "MuWire $e.version has been downloaded. You can update now", Map<String, Object> args = new HashMap<>()
"Update Downloaded", JOptionPane.INFORMATION_MESSAGE) args['available'] = null
args['downloaded'] = e
mvcGroup.createMVCGroup("update", "update", args)
} }
} }
@@ -529,13 +532,10 @@ class MainFrameModel {
void onUpdateAvailableEvent(UpdateAvailableEvent e) { void onUpdateAvailableEvent(UpdateAvailableEvent e) {
runInsideUIAsync { runInsideUIAsync {
Map<String, Object> args = new HashMap<>()
int option = JOptionPane.showConfirmDialog(null, args['available'] = e
"MuWire $e.version is available from $e.signer. You have "+ metadata["application.version"]+" Update?", args['downloaded'] = null
"New MuWire version availble", JOptionPane.OK_CANCEL_OPTION) mvcGroup.createMVCGroup("update", "update", args)
if (option == JOptionPane.CANCEL_OPTION)
return
controller.search(e.infoHash,"MuWire update")
} }
} }

View File

@@ -0,0 +1,14 @@
package com.muwire.gui
import com.muwire.core.update.UpdateAvailableEvent
import com.muwire.core.update.UpdateDownloadedEvent
import griffon.core.artifact.GriffonModel
import griffon.transform.Observable
import griffon.metadata.ArtifactProviderFor
@ArtifactProviderFor(GriffonModel)
class UpdateModel {
UpdateAvailableEvent available
UpdateDownloadedEvent downloaded
}

View File

@@ -0,0 +1,61 @@
package com.muwire.gui
import griffon.core.artifact.GriffonView
import griffon.inject.MVCMember
import griffon.metadata.ArtifactProviderFor
import javax.swing.JDialog
import javax.swing.SwingConstants
import java.awt.BorderLayout
import java.awt.event.WindowAdapter
import java.awt.event.WindowEvent
import javax.annotation.Nonnull
@ArtifactProviderFor(GriffonView)
class UpdateView {
@MVCMember @Nonnull
FactoryBuilderSupport builder
@MVCMember @Nonnull
UpdateModel model
def mainFrame
def dialog
def p
void initUI() {
mainFrame = application.windowManager.findWindow("main-frame")
String title = model.downloaded != null ? "Update Downloaded" : "Update Available"
dialog = new JDialog(mainFrame, title, true)
dialog.setResizable(true)
p = builder.panel {
borderLayout()
panel (constraints : BorderLayout.CENTER) {
scrollPane {
def text = model.downloaded != null ? model.downloaded.text : model.available.text
textArea(text : text, rows : 20, columns : 50, editable : false, lineWrap : true, wrapStyleWord : true)
}
}
panel (constraints : BorderLayout.SOUTH) {
if (model.available != null)
button(text : "Find", searchAction)
button(text : "Close", closeAction)
}
}
}
void mvcGroupInit(Map<String,String> args) {
dialog.getContentPane().add(p)
dialog.pack()
dialog.setLocationRelativeTo(mainFrame)
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
dialog.addWindowListener( new WindowAdapter() {
public void windowClosed(WindowEvent e) {
mvcGroup.destroy()
}
})
dialog.show()
}
}