mirror of https://github.com/zlatinb/muwire
auto updates
parent
2a4cdc565b
commit
722bc09aa6
|
@ -8,6 +8,8 @@ import com.muwire.core.files.directories.WatchedDirectoriesLoadedEvent
|
|||
import com.muwire.core.messenger.UIFolderCreateEvent
|
||||
import com.muwire.core.messenger.UIFolderDeleteEvent
|
||||
import com.muwire.core.messenger.UIMessageMovedEvent
|
||||
import com.muwire.core.update.AutoUpdater
|
||||
import com.muwire.core.update.UpdateDownloadedEvent
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
@ -530,6 +532,14 @@ public class Core {
|
|||
register(UIMessageMovedEvent.class, messenger)
|
||||
}
|
||||
|
||||
if (System.hasProperty("auto.updater.class")) {
|
||||
String className = System.getProperty("auto.updater.class")
|
||||
log.info("initializing auto-updater $className")
|
||||
Class<?> clazz = Class.forName(className))
|
||||
AutoUpdater autoUpdater = (AutoUpdater) clazz.newInstance()
|
||||
autoUpdater.init(this)
|
||||
}
|
||||
|
||||
File modulesProps = new File(home, "mwmodules.list")
|
||||
if (modulesProps.exists()) {
|
||||
log.info("loading modules")
|
||||
|
@ -539,6 +549,13 @@ public class Core {
|
|||
modules.add(module)
|
||||
}
|
||||
}
|
||||
|
||||
eventBus.register(RestartEvent.class, this)
|
||||
}
|
||||
|
||||
void onRestartEvent(RestartEvent event) {
|
||||
shutdown()
|
||||
System.exit(0)
|
||||
}
|
||||
|
||||
public void startServices() {
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package com.muwire.core
|
||||
|
||||
/** triggers a restart of MuWire */
|
||||
class RestartEvent extends Event{
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.muwire.core.update;
|
||||
|
||||
import com.muwire.core.Core;
|
||||
|
||||
public interface AutoUpdater {
|
||||
void init(Core core);
|
||||
}
|
|
@ -89,7 +89,8 @@ class UpdateClient {
|
|||
if (e.infoHash != updateInfoHash)
|
||||
return
|
||||
updateDownloading = false
|
||||
eventBus.publish(new UpdateDownloadedEvent(version : version, signer : signer, text : text))
|
||||
eventBus.publish(new UpdateDownloadedEvent(version : version, signer : signer,
|
||||
text : text, updateFile: e.downloadedFile.file))
|
||||
}
|
||||
|
||||
private void checkUpdate() {
|
||||
|
@ -192,9 +193,11 @@ class UpdateClient {
|
|||
} 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, text : text))
|
||||
else {
|
||||
if (fileManager.rootToFiles.containsKey(updateInfoHash)) {
|
||||
File updateFile = fileManager.rootToFiles.get(updateInfoHash).first().file
|
||||
eventBus.publish(new UpdateDownloadedEvent(version: payload.version, signer: payload.signer,
|
||||
text : text, updateFile: updateFile))
|
||||
} else {
|
||||
updateDownloading = false
|
||||
version = payload.version
|
||||
signer = payload.signer
|
||||
|
|
|
@ -6,4 +6,5 @@ class UpdateDownloadedEvent extends Event {
|
|||
String version
|
||||
String signer
|
||||
String text
|
||||
File updateFile
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muwire.gui
|
||||
|
||||
import com.muwire.core.RestartEvent
|
||||
import griffon.core.artifact.GriffonController
|
||||
import griffon.core.controller.ControllerAction
|
||||
import griffon.inject.MVCMember
|
||||
|
@ -16,7 +17,11 @@ class UpdateController {
|
|||
@ControllerAction
|
||||
void close() {
|
||||
view.dialog.setVisible(false)
|
||||
mvcGroup.destroy()
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
void restart() {
|
||||
model.core.eventBus.publish(new RestartEvent())
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
|
|
|
@ -495,6 +495,7 @@ EXIT_MUWIRE=Exit MuWire
|
|||
UPDATE_DOWNLOADED=Update Downloaded
|
||||
UPDATE_AVAILABLE=Update Available
|
||||
FIND=Find
|
||||
RESTART=Restart
|
||||
|
||||
## Advanced Sharing tool
|
||||
DIRECTORIES_WATCHED_FOR_CHANGES=Folders watched for file changes
|
||||
|
@ -826,5 +827,9 @@ TOOLTIP_RULE_RECORD=Record queries that match this rule
|
|||
TOOLTIP_RULE_DROP=Drop queries that match this rule
|
||||
TOOLTIP_RULE_BLOCK=Mark the sender of queries that match this rule as Distrusted
|
||||
|
||||
### Tooltips for update dialog
|
||||
TOOLTIP_FIND=Search for the update
|
||||
TOOLTIP_RESTART=Update and restart MuWire
|
||||
|
||||
## Test string
|
||||
TEST_PLURALIZABLE_STRING={count, plural, one {You have {count} item.} other {You have {count} items.}}
|
||||
|
|
|
@ -390,6 +390,7 @@ class MainFrameModel {
|
|||
void onUpdateDownloadedEvent(UpdateDownloadedEvent e) {
|
||||
runInsideUIAsync {
|
||||
Map<String, Object> args = new HashMap<>()
|
||||
args['core'] = core
|
||||
args['available'] = null
|
||||
args['downloaded'] = e
|
||||
mvcGroup.createMVCGroup("update", "update", args)
|
||||
|
@ -774,6 +775,7 @@ class MainFrameModel {
|
|||
void onUpdateAvailableEvent(UpdateAvailableEvent e) {
|
||||
runInsideUIAsync {
|
||||
Map<String, Object> args = new HashMap<>()
|
||||
args['core'] = core
|
||||
args['available'] = e
|
||||
args['downloaded'] = null
|
||||
mvcGroup.createMVCGroup("update", "update", args)
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package com.muwire.gui
|
||||
|
||||
import com.muwire.core.Core
|
||||
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 {
|
||||
Core core
|
||||
UpdateAvailableEvent available
|
||||
UpdateDownloadedEvent downloaded
|
||||
}
|
|
@ -41,7 +41,9 @@ class UpdateView {
|
|||
}
|
||||
panel (constraints : BorderLayout.SOUTH) {
|
||||
if (model.available != null)
|
||||
button(text : trans("FIND"), searchAction)
|
||||
button(text : trans("FIND"), toolTipText: trans("TOOLTIP_FIND"), searchAction)
|
||||
else if (model.downloaded != null)
|
||||
button(text : trans("RESTART"), toolTipText: trans("TOOLTIP_RESTART"), restartAction)
|
||||
button(text : trans("CLOSE"), closeAction)
|
||||
}
|
||||
}
|
||||
|
@ -52,11 +54,6 @@ class UpdateView {
|
|||
dialog.pack()
|
||||
dialog.setLocationRelativeTo(mainFrame)
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
|
||||
dialog.addWindowListener( new WindowAdapter() {
|
||||
public void windowClosed(WindowEvent e) {
|
||||
mvcGroup.destroy()
|
||||
}
|
||||
})
|
||||
dialog.show()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue