Add update notification window
This commit is contained in:
@ -7,4 +7,5 @@ class UpdateAvailableEvent extends Event {
|
||||
String version
|
||||
String signer
|
||||
String infoHash
|
||||
String text
|
||||
}
|
||||
|
@ -40,6 +40,8 @@ class UpdateClient {
|
||||
private volatile InfoHash updateInfoHash
|
||||
private volatile String version, signer
|
||||
private volatile boolean updateDownloading
|
||||
|
||||
private volatile String text
|
||||
|
||||
UpdateClient(EventBus eventBus, I2PSession session, String myVersion, MuWireSettings settings, FileManager fileManager, Persona me) {
|
||||
this.eventBus = eventBus
|
||||
@ -75,7 +77,7 @@ class UpdateClient {
|
||||
if (e.downloadedFile.infoHash != updateInfoHash)
|
||||
return
|
||||
updateDownloading = false
|
||||
eventBus.publish(new UpdateDownloadedEvent(version : version, signer : signer))
|
||||
eventBus.publish(new UpdateDownloadedEvent(version : version, signer : signer, text : text))
|
||||
}
|
||||
|
||||
private void checkUpdate() {
|
||||
@ -147,15 +149,16 @@ class UpdateClient {
|
||||
} else
|
||||
infoHash = payload[settings.updateType]
|
||||
|
||||
|
||||
text = payload.text
|
||||
|
||||
if (!settings.autoDownloadUpdate) {
|
||||
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 {
|
||||
log.info("new version $payload.version available")
|
||||
updateInfoHash = new InfoHash(Base64.decode(infoHash))
|
||||
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 {
|
||||
updateDownloading = false
|
||||
version = payload.version
|
||||
|
@ -5,4 +5,5 @@ import com.muwire.core.Event
|
||||
class UpdateDownloadedEvent extends Event {
|
||||
String version
|
||||
String signer
|
||||
String text
|
||||
}
|
||||
|
@ -76,4 +76,9 @@ mvcGroups {
|
||||
view = 'com.muwire.gui.CloseWarningView'
|
||||
controller = 'com.muwire.gui.CloseWarningController'
|
||||
}
|
||||
'update' {
|
||||
model = 'com.muwire.gui.UpdateModel'
|
||||
view = 'com.muwire.gui.UpdateView'
|
||||
controller = 'com.muwire.gui.UpdateController'
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
|
||||
package com.muwire.gui
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
@ -264,8 +265,10 @@ class MainFrameModel {
|
||||
|
||||
void onUpdateDownloadedEvent(UpdateDownloadedEvent e) {
|
||||
runInsideUIAsync {
|
||||
JOptionPane.showMessageDialog(null, "MuWire $e.version has been downloaded. You can update now",
|
||||
"Update Downloaded", JOptionPane.INFORMATION_MESSAGE)
|
||||
Map<String, Object> args = new HashMap<>()
|
||||
args['available'] = null
|
||||
args['downloaded'] = e
|
||||
mvcGroup.createMVCGroup("update", "update", args)
|
||||
}
|
||||
}
|
||||
|
||||
@ -529,13 +532,10 @@ class MainFrameModel {
|
||||
|
||||
void onUpdateAvailableEvent(UpdateAvailableEvent e) {
|
||||
runInsideUIAsync {
|
||||
|
||||
int option = JOptionPane.showConfirmDialog(null,
|
||||
"MuWire $e.version is available from $e.signer. You have "+ metadata["application.version"]+" Update?",
|
||||
"New MuWire version availble", JOptionPane.OK_CANCEL_OPTION)
|
||||
if (option == JOptionPane.CANCEL_OPTION)
|
||||
return
|
||||
controller.search(e.infoHash,"MuWire update")
|
||||
Map<String, Object> args = new HashMap<>()
|
||||
args['available'] = e
|
||||
args['downloaded'] = null
|
||||
mvcGroup.createMVCGroup("update", "update", args)
|
||||
}
|
||||
}
|
||||
|
||||
|
14
gui/griffon-app/models/com/muwire/gui/UpdateModel.groovy
Normal file
14
gui/griffon-app/models/com/muwire/gui/UpdateModel.groovy
Normal 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
|
||||
}
|
61
gui/griffon-app/views/com/muwire/gui/UpdateView.groovy
Normal file
61
gui/griffon-app/views/com/muwire/gui/UpdateView.groovy
Normal 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()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user