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.UIFolderCreateEvent
|
||||||
import com.muwire.core.messenger.UIFolderDeleteEvent
|
import com.muwire.core.messenger.UIFolderDeleteEvent
|
||||||
import com.muwire.core.messenger.UIMessageMovedEvent
|
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.nio.charset.StandardCharsets
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
@ -530,6 +532,14 @@ public class Core {
|
||||||
register(UIMessageMovedEvent.class, messenger)
|
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")
|
File modulesProps = new File(home, "mwmodules.list")
|
||||||
if (modulesProps.exists()) {
|
if (modulesProps.exists()) {
|
||||||
log.info("loading modules")
|
log.info("loading modules")
|
||||||
|
@ -539,6 +549,13 @@ public class Core {
|
||||||
modules.add(module)
|
modules.add(module)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eventBus.register(RestartEvent.class, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
void onRestartEvent(RestartEvent event) {
|
||||||
|
shutdown()
|
||||||
|
System.exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startServices() {
|
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)
|
if (e.infoHash != updateInfoHash)
|
||||||
return
|
return
|
||||||
updateDownloading = false
|
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() {
|
private void checkUpdate() {
|
||||||
|
@ -192,9 +193,11 @@ class UpdateClient {
|
||||||
} 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, text : text))
|
File updateFile = fileManager.rootToFiles.get(updateInfoHash).first().file
|
||||||
else {
|
eventBus.publish(new UpdateDownloadedEvent(version: payload.version, signer: payload.signer,
|
||||||
|
text : text, updateFile: updateFile))
|
||||||
|
} else {
|
||||||
updateDownloading = false
|
updateDownloading = false
|
||||||
version = payload.version
|
version = payload.version
|
||||||
signer = payload.signer
|
signer = payload.signer
|
||||||
|
|
|
@ -6,4 +6,5 @@ class UpdateDownloadedEvent extends Event {
|
||||||
String version
|
String version
|
||||||
String signer
|
String signer
|
||||||
String text
|
String text
|
||||||
|
File updateFile
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.muwire.gui
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import com.muwire.core.RestartEvent
|
||||||
import griffon.core.artifact.GriffonController
|
import griffon.core.artifact.GriffonController
|
||||||
import griffon.core.controller.ControllerAction
|
import griffon.core.controller.ControllerAction
|
||||||
import griffon.inject.MVCMember
|
import griffon.inject.MVCMember
|
||||||
|
@ -16,7 +17,11 @@ class UpdateController {
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
void close() {
|
void close() {
|
||||||
view.dialog.setVisible(false)
|
view.dialog.setVisible(false)
|
||||||
mvcGroup.destroy()
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void restart() {
|
||||||
|
model.core.eventBus.publish(new RestartEvent())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
|
|
|
@ -495,6 +495,7 @@ EXIT_MUWIRE=Exit MuWire
|
||||||
UPDATE_DOWNLOADED=Update Downloaded
|
UPDATE_DOWNLOADED=Update Downloaded
|
||||||
UPDATE_AVAILABLE=Update Available
|
UPDATE_AVAILABLE=Update Available
|
||||||
FIND=Find
|
FIND=Find
|
||||||
|
RESTART=Restart
|
||||||
|
|
||||||
## Advanced Sharing tool
|
## Advanced Sharing tool
|
||||||
DIRECTORIES_WATCHED_FOR_CHANGES=Folders watched for file changes
|
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_DROP=Drop queries that match this rule
|
||||||
TOOLTIP_RULE_BLOCK=Mark the sender of queries that match this rule as Distrusted
|
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 string
|
||||||
TEST_PLURALIZABLE_STRING={count, plural, one {You have {count} item.} other {You have {count} items.}}
|
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) {
|
void onUpdateDownloadedEvent(UpdateDownloadedEvent e) {
|
||||||
runInsideUIAsync {
|
runInsideUIAsync {
|
||||||
Map<String, Object> args = new HashMap<>()
|
Map<String, Object> args = new HashMap<>()
|
||||||
|
args['core'] = core
|
||||||
args['available'] = null
|
args['available'] = null
|
||||||
args['downloaded'] = e
|
args['downloaded'] = e
|
||||||
mvcGroup.createMVCGroup("update", "update", args)
|
mvcGroup.createMVCGroup("update", "update", args)
|
||||||
|
@ -774,6 +775,7 @@ class MainFrameModel {
|
||||||
void onUpdateAvailableEvent(UpdateAvailableEvent e) {
|
void onUpdateAvailableEvent(UpdateAvailableEvent e) {
|
||||||
runInsideUIAsync {
|
runInsideUIAsync {
|
||||||
Map<String, Object> args = new HashMap<>()
|
Map<String, Object> args = new HashMap<>()
|
||||||
|
args['core'] = core
|
||||||
args['available'] = e
|
args['available'] = e
|
||||||
args['downloaded'] = null
|
args['downloaded'] = null
|
||||||
mvcGroup.createMVCGroup("update", "update", args)
|
mvcGroup.createMVCGroup("update", "update", args)
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
package com.muwire.gui
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import com.muwire.core.Core
|
||||||
import com.muwire.core.update.UpdateAvailableEvent
|
import com.muwire.core.update.UpdateAvailableEvent
|
||||||
import com.muwire.core.update.UpdateDownloadedEvent
|
import com.muwire.core.update.UpdateDownloadedEvent
|
||||||
|
|
||||||
import griffon.core.artifact.GriffonModel
|
import griffon.core.artifact.GriffonModel
|
||||||
import griffon.transform.Observable
|
|
||||||
import griffon.metadata.ArtifactProviderFor
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
|
||||||
@ArtifactProviderFor(GriffonModel)
|
@ArtifactProviderFor(GriffonModel)
|
||||||
class UpdateModel {
|
class UpdateModel {
|
||||||
|
Core core
|
||||||
UpdateAvailableEvent available
|
UpdateAvailableEvent available
|
||||||
UpdateDownloadedEvent downloaded
|
UpdateDownloadedEvent downloaded
|
||||||
}
|
}
|
|
@ -41,7 +41,9 @@ class UpdateView {
|
||||||
}
|
}
|
||||||
panel (constraints : BorderLayout.SOUTH) {
|
panel (constraints : BorderLayout.SOUTH) {
|
||||||
if (model.available != null)
|
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)
|
button(text : trans("CLOSE"), closeAction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,11 +54,6 @@ class UpdateView {
|
||||||
dialog.pack()
|
dialog.pack()
|
||||||
dialog.setLocationRelativeTo(mainFrame)
|
dialog.setLocationRelativeTo(mainFrame)
|
||||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
|
||||||
dialog.addWindowListener( new WindowAdapter() {
|
|
||||||
public void windowClosed(WindowEvent e) {
|
|
||||||
mvcGroup.destroy()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
dialog.show()
|
dialog.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue