From 5717e86305a059e3534b4e9a1fcc6910f0da32f0 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 1 Oct 2021 12:46:51 +0300 Subject: [PATCH] Implement product version reporting --- .github/workflows/release.yml | 2 +- gobridge/gobridge.go | 43 ++++++++++++------------------ gobridge/gobridge.h | 6 ++--- launcher.xcodeproj/project.pbxproj | 4 +-- launcher/AppDelegate.m | 4 ++- launcher/Model.h | 2 +- launcher/Model.m | 16 ++++++++--- launcher/NetworkingModalDelegate.m | 2 +- 8 files changed, 40 insertions(+), 39 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 86213b9..57a9fa4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,7 +24,7 @@ jobs: git clone https://github.com/mysteriumnetwork/myst-launcher pushd myst-launcher git fetch --all --tags - git checkout tags/1.0.13 + git checkout tags/1.0.14 popd popd diff --git a/gobridge/gobridge.go b/gobridge/gobridge.go index 27d7a3e..834568d 100644 --- a/gobridge/gobridge.go +++ b/gobridge/gobridge.go @@ -21,7 +21,7 @@ import ( var ( manager *myst.Manager - cfg model.Config + //cfg model.Config mon *myst.DockerMonitor mod *model.UIModel @@ -49,21 +49,21 @@ func copyFile(sourceFile, destinationFile string) { } //export GoInit -func GoInit(res_path *C.char) { - cfg.ResourcePath = C.GoString(res_path) +func GoInit(resPath *C.char, prodVer *C.char) { + mod = model.NewUIModel() + mod.Config.ProductVersion = C.GoString(prodVer) targetDir := os.Getenv("HOME") + "/Library/LaunchAgents/" os.MkdirAll(targetDir, 0755) - fileName := "com.mysterium.launcher.plist" - copyFile(cfg.ResourcePath+"/"+fileName, targetDir+fileName) + resourcePath := C.GoString(resPath) + copyFile(resourcePath+"/"+fileName, targetDir+fileName) } //export GoStart func GoStart() { fmt.Println("GoStart >") ap = app.NewApp() - mod = model.NewUIModel() sendConfig() mod.UIBus.Subscribe("state-change", func() { @@ -141,19 +141,12 @@ func GoTriggerUpgrade() { ap.TriggerAction("upgrade") } -//export GoTriggerRefresh -func GoTriggerRefresh() { - ap.TriggerAction("refresh") -} - -//export GoSetStateAndConfig -func GoSetStateAndConfig(s *C.SetStateArgs) { - fmt.Println("SetState >", s) - saveConf := false +//export GoSetState +func GoSetState(s *C.SetStateArgs) { if mod.Config.AutoUpgrade != bool(s.autoUpgrade) { mod.Config.AutoUpgrade = bool(s.autoUpgrade) - saveConf = true + mod.Config.Save() } if mod.Config.Enabled != bool(s.enabled) { @@ -163,20 +156,18 @@ func GoSetStateAndConfig(s *C.SetStateArgs) { ap.TriggerAction("disable") } } +} - if mod.Config.EnablePortForwarding != bool(s.enablePortForwarding) || mod.Config.PortRangeBegin != int(s.portRangeBegin) || mod.Config.PortRangeEnd != int(s.portRangeEnd) { - mod.Config.EnablePortForwarding = bool(s.enablePortForwarding) - mod.Config.PortRangeBegin = int(s.portRangeBegin) - mod.Config.PortRangeEnd = int(s.portRangeEnd) +//export GoSetNetworkConfig +func GoSetNetworkConfig(s *C.SetStateArgs) { - ap.TriggerAction("upgrade") - saveConf = true - } + mod.Config.EnablePortForwarding = bool(s.enablePortForwarding) + mod.Config.PortRangeBegin = int(s.portRangeBegin) + mod.Config.PortRangeEnd = int(s.portRangeEnd) - if saveConf { - mod.Config.Save() - } + ap.TriggerAction("restart") } + // required by runtime func main() {} diff --git a/gobridge/gobridge.h b/gobridge/gobridge.h index 1fa0073..7c375fa 100644 --- a/gobridge/gobridge.h +++ b/gobridge/gobridge.h @@ -76,14 +76,14 @@ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; extern "C" { #endif -extern void GoInit(char* res_path); +extern void GoInit(char* resPath, char* prodVer); extern void GoStart(); extern void GoSetModalResult(int rc); extern void GoDialogueComplete(); extern void GoOnAppExit(); extern void GoTriggerUpgrade(); -extern void GoTriggerRefresh(); -extern void GoSetStateAndConfig(SetStateArgs* s); +extern void GoSetState(SetStateArgs* s); +extern void GoSetNetworkConfig(SetStateArgs* s); #ifdef __cplusplus } diff --git a/launcher.xcodeproj/project.pbxproj b/launcher.xcodeproj/project.pbxproj index 4fe5a88..f13966b 100644 --- a/launcher.xcodeproj/project.pbxproj +++ b/launcher.xcodeproj/project.pbxproj @@ -538,7 +538,7 @@ "$(PROJECT_DIR)/gobridge", "$(PROJECT_DIR)", ); - MARKETING_VERSION = 1.0.12; + MARKETING_VERSION = 1.0.14; PRODUCT_BUNDLE_IDENTIFIER = com.mysterium.launcher; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -566,7 +566,7 @@ "$(PROJECT_DIR)/gobridge", "$(PROJECT_DIR)", ); - MARKETING_VERSION = 1.0.12; + MARKETING_VERSION = 1.0.14; PRODUCT_BUNDLE_IDENTIFIER = com.mysterium.launcher; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/launcher/AppDelegate.m b/launcher/AppDelegate.m index c4a006c..20f1c3c 100644 --- a/launcher/AppDelegate.m +++ b/launcher/AppDelegate.m @@ -27,7 +27,9 @@ - (void) applicationWillTerminate:(NSNotification *)aNotification { - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSString *resourcePath = [[NSBundle mainBundle] resourcePath]; - GoInit((char*)[resourcePath UTF8String]); + id productVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]; + + GoInit((char*)[resourcePath UTF8String], (char*)[productVersion UTF8String]); GoStart(); mod = [[LauncherState alloc] init]; diff --git a/launcher/Model.h b/launcher/Model.h index bb6040c..556cac6 100644 --- a/launcher/Model.h +++ b/launcher/Model.h @@ -55,7 +55,7 @@ - (void)setState; - +- (void)setNetworkConfig; @end #endif /* model_h */ diff --git a/launcher/Model.m b/launcher/Model.m index 945cda6..65617a7 100644 --- a/launcher/Model.m +++ b/launcher/Model.m @@ -42,6 +42,8 @@ - (id) init } - (void)notificationHandlerState:(NSNotification *) notification{ +// NSLog(@"notificationHandlerState > %@", notification.userInfo); + self.imageName = notification.userInfo[@"imageName"]; self.hasUpdate = notification.userInfo[@"hasUpdate"]; self.currentVersion = notification.userInfo[@"currentVersion"]; @@ -54,7 +56,6 @@ - (void)notificationHandlerState:(NSNotification *) notification{ self.downloadFiles = notification.userInfo[@"downloadFiles"]; self.installDocker = notification.userInfo[@"installDocker"]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"new_state" object:nil]; } @@ -104,13 +105,20 @@ - (void)notificationHandlerModal:(NSNotification *) notification{ - (void)setState { SetStateArgs s; + s.autoUpgrade = [self.autoUpgrade boolValue]; + s.enabled = [self.enabled boolValue]; + + GoSetState(&s); +} + +- (void)setNetworkConfig { + SetStateArgs s; + s.enablePortForwarding = [self.enablePortForwarding boolValue]; s.portRangeBegin = [self.portBegin intValue]; s.portRangeEnd = [self.portEnd intValue]; - s.autoUpgrade = [self.autoUpgrade boolValue]; - s.enabled = [self.enabled boolValue]; - GoSetStateAndConfig(&s); + GoSetNetworkConfig(&s); } @end diff --git a/launcher/NetworkingModalDelegate.m b/launcher/NetworkingModalDelegate.m index 1d20223..7154d88 100644 --- a/launcher/NetworkingModalDelegate.m +++ b/launcher/NetworkingModalDelegate.m @@ -76,7 +76,7 @@ - (IBAction)okPressed:(id)sender mod.portBegin = @(portBegin); mod.portEnd = @(portEnd); mod.enablePortForwarding = [NSNumber numberWithBool:[self.checkBox integerValue]]; - [mod setState]; + [mod setNetworkConfig]; [self close]; [NSApp stopModalWithCode:NSModalResponseOK];