-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
3,830 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module github.com/mysteriumnetwork/fff | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/Microsoft/go-winio v0.5.0 // indirect | ||
github.com/buger/jsonparser v1.1.1 // indirect | ||
github.com/containerd/containerd v1.5.5 // indirect | ||
github.com/docker/docker v20.10.8+incompatible // indirect | ||
github.com/gorilla/mux v1.8.0 // indirect | ||
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect | ||
github.com/mysteriumnetwork/myst-launcher v0.0.0 | ||
github.com/stretchr/testify v1.7.0 // indirect | ||
github.com/winlabs/gowin32 v0.0.0-20210302152218-c9e40aa88058 // indirect | ||
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect | ||
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect | ||
google.golang.org/grpc v1.40.0 // indirect | ||
) | ||
|
||
replace github.com/mysteriumnetwork/myst-launcher => ../../myst-launcher |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package main | ||
|
||
/* | ||
#cgo CFLAGS: -x objective-c | ||
#cgo LDFLAGS: -framework Foundation | ||
#cgo LDFLAGS: -L./ -linterface.o | ||
#include "interface.h" | ||
*/ | ||
import "C" | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/mysteriumnetwork/myst-launcher/app" | ||
"github.com/mysteriumnetwork/myst-launcher/model" | ||
"github.com/mysteriumnetwork/myst-launcher/myst" | ||
) | ||
|
||
var ( | ||
manager *myst.Manager | ||
cfg model.Config | ||
mon *myst.DockerMonitor | ||
mod *model.UIModel | ||
|
||
ap *app.AppState | ||
ui model.Gui_ | ||
) | ||
|
||
func init() { | ||
fmt.Println("gobridge init>") | ||
ap = app.NewApp() | ||
|
||
mod = model.NewUIModel() | ||
sendConfig() | ||
|
||
mod.UIBus.Subscribe("state-change", func() { | ||
C.macSendMode(C.int(mod.State)) | ||
}) | ||
mod.UIBus.Subscribe("log", func(p []byte) { | ||
C.macSendLog(C.CString(string(p))) | ||
}) | ||
log.SetOutput(ap) | ||
|
||
mod.UIBus.Subscribe("model-change", sendState) | ||
ui = newUiProxy() | ||
|
||
mod.SetApp(ap) | ||
ap.SetModel(mod) | ||
ap.SetUI(ui) | ||
|
||
ap.WaitGroup.Add(1) | ||
go ap.SuperviseDockerNode() | ||
} | ||
|
||
func sendState() { | ||
var st C.NSState | ||
|
||
st.imageName = C.CString(mod.ImgVer.ImageName) | ||
st.currentVersion = C.CString(mod.ImgVer.VersionCurrent) | ||
st.latestVersion = C.CString(mod.ImgVer.VersionLatest) | ||
st.hasUpdate = C.bool(mod.ImgVer.HasUpdate) | ||
st.dockerRunning = C.int(mod.StateDocker) | ||
st.containerRunning = C.int(mod.StateContainer) | ||
|
||
// instllation state | ||
st.checkVTx = C.bool(mod.CheckVTx) | ||
st.checkDocker = C.bool(mod.CheckDocker) | ||
|
||
C.macSendState(&st) | ||
} | ||
|
||
func sendConfig() { | ||
var cf C.NSConfig | ||
|
||
cf.enablePortForwarding = C.bool(mod.Config.EnablePortForwarding) | ||
cf.portRangeBegin = C.int(mod.Config.PortRangeBegin) | ||
cf.portRangeEnd = C.int(mod.Config.PortRangeEnd) | ||
cf.autoUpgrade = C.bool(mod.Config.AutoUpgrade) | ||
cf.enabled = C.bool(mod.Config.Enabled) | ||
|
||
C.macSendConfig(&cf) | ||
} | ||
|
||
//export GoSetModalResult | ||
func GoSetModalResult(rc C.int) { | ||
fmt.Println("CloseModal >", int(rc)) | ||
ui.SetModalReturnCode(int(rc)) | ||
} | ||
|
||
//export GoDialogueComplete | ||
func GoDialogueComplete() { | ||
fmt.Println("DialogueComplete >") | ||
ui.DialogueComplete() | ||
} | ||
|
||
//export GoOnAppExit | ||
func GoOnAppExit() { | ||
fmt.Println("OnAppExit >") | ||
|
||
ap.TriggerAction("stop") | ||
// wait for SuperviseDockerNode to finish its work | ||
ap.WaitGroup.Wait() | ||
} | ||
|
||
//export GoSetStateAndConfig | ||
func GoSetStateAndConfig(s *C.SetStateArgs) { | ||
fmt.Println("SetState >", s) | ||
saveConf := false | ||
|
||
if mod.Config.AutoUpgrade != bool(s.autoUpgrade) { | ||
mod.Config.AutoUpgrade = bool(s.autoUpgrade) | ||
saveConf = true | ||
} | ||
|
||
if mod.Config.Enabled != bool(s.enabled) { | ||
if bool(s.enabled) { | ||
ap.TriggerAction("enable") | ||
} else { | ||
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) | ||
|
||
ap.TriggerAction("upgrade") | ||
saveConf = true | ||
} | ||
|
||
if saveConf { | ||
mod.Config.Save() | ||
} | ||
} | ||
|
||
// required by runtime | ||
func main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* Code generated by cmd/cgo; DO NOT EDIT. */ | ||
|
||
/* package command-line-arguments */ | ||
|
||
|
||
#line 1 "cgo-builtin-export-prolog" | ||
|
||
#include <stddef.h> /* for ptrdiff_t below */ | ||
|
||
#ifndef GO_CGO_EXPORT_PROLOGUE_H | ||
#define GO_CGO_EXPORT_PROLOGUE_H | ||
|
||
#ifndef GO_CGO_GOSTRING_TYPEDEF | ||
typedef struct { const char *p; ptrdiff_t n; } _GoString_; | ||
#endif | ||
|
||
#endif | ||
|
||
/* Start of preamble from import "C" comments. */ | ||
|
||
|
||
#line 3 "gobridge.go" | ||
|
||
|
||
|
||
|
||
#include "interface.h" | ||
|
||
#line 1 "cgo-generated-wrapper" | ||
|
||
|
||
/* End of preamble from import "C" comments. */ | ||
|
||
|
||
/* Start of boilerplate cgo prologue. */ | ||
#line 1 "cgo-gcc-export-header-prolog" | ||
|
||
#ifndef GO_CGO_PROLOGUE_H | ||
#define GO_CGO_PROLOGUE_H | ||
|
||
typedef signed char GoInt8; | ||
typedef unsigned char GoUint8; | ||
typedef short GoInt16; | ||
typedef unsigned short GoUint16; | ||
typedef int GoInt32; | ||
typedef unsigned int GoUint32; | ||
typedef long long GoInt64; | ||
typedef unsigned long long GoUint64; | ||
typedef GoInt64 GoInt; | ||
typedef GoUint64 GoUint; | ||
typedef __SIZE_TYPE__ GoUintptr; | ||
typedef float GoFloat32; | ||
typedef double GoFloat64; | ||
typedef float _Complex GoComplex64; | ||
typedef double _Complex GoComplex128; | ||
|
||
/* | ||
static assertion to make sure the file is being used on architecture | ||
at least with matching size of GoInt. | ||
*/ | ||
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1]; | ||
|
||
#ifndef GO_CGO_GOSTRING_TYPEDEF | ||
typedef _GoString_ GoString; | ||
#endif | ||
typedef void *GoMap; | ||
typedef void *GoChan; | ||
typedef struct { void *t; void *v; } GoInterface; | ||
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice; | ||
|
||
#endif | ||
|
||
/* End of boilerplate cgo prologue. */ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern void GoSetModalResult(int rc); | ||
extern void GoDialogueComplete(); | ||
extern void GoOnAppExit(); | ||
extern void GoSetStateAndConfig(SetStateArgs* s); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
|
||
typedef struct _NSState { | ||
char *imageName; | ||
char *currentVersion; | ||
char *latestVersion; | ||
bool hasUpdate; | ||
int dockerRunning; | ||
int containerRunning; | ||
|
||
bool checkVTx; | ||
bool checkDocker; | ||
} NSState; | ||
|
||
typedef struct _NSConfig { | ||
bool autoUpgrade; | ||
bool enabled; | ||
bool enablePortForwarding; | ||
int portRangeBegin; | ||
int portRangeEnd; | ||
} NSConfig; | ||
|
||
typedef struct _NSModal { | ||
char *title; | ||
char *msg; | ||
int modal_type; | ||
} NSModal; | ||
|
||
|
||
typedef struct _SetStateArgs { | ||
bool enablePortForwarding; | ||
int portRangeBegin; | ||
int portRangeEnd; | ||
bool autoUpgrade; | ||
bool enabled; | ||
} SetStateArgs; | ||
|
||
|
||
|
||
/// | ||
void macSendState(NSState *s); | ||
void macSendConfig(NSConfig *s); | ||
void macSendModal(NSModal *s); | ||
void macSendMode(int s); | ||
void macSendLog(char *s); | ||
|
||
/// | ||
typedef enum { | ||
IDOK = 1, | ||
IDCANCEL = 2, | ||
IDABORT = 3, | ||
IDRETRY = 4, | ||
IDIGNORE = 5, | ||
IDYES = 6, | ||
IDNO = 7, | ||
IDCLOSE = 8, | ||
IDHELP = 9, | ||
IDTRYAGAIN = 10, | ||
IDCONTINUE = 11, | ||
IDTIMEOUT = 32000 | ||
} MODAL_RESULT; | ||
|
||
typedef enum { | ||
MODAL_ConfirmModal = 1, | ||
MODAL_YesNoModal = 2, | ||
MODAL_ErrorModal = 3, | ||
} MODAL_TYPE; | ||
|
||
typedef enum { | ||
UIState_Initial = 0, | ||
UIState_InstallNeeded = -1, | ||
UIState_InstallInProgress = -2, | ||
UIState_InstallFinished = -3, | ||
UIState_InstallError = -4, | ||
} UI_STATE; | ||
|
Oops, something went wrong.