Skip to content

Commit

Permalink
Add UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Zensey authored Sep 13, 2021
1 parent 784371f commit b87f27d
Show file tree
Hide file tree
Showing 55 changed files with 3,830 additions and 45 deletions.
48 changes: 3 additions & 45 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
.DS_Store
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
Expand All @@ -30,39 +21,6 @@ DerivedData/
*.dSYM.zip
*.dSYM

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# fastlane
#
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/
*.dylib
*.o
20 changes: 20 additions & 0 deletions gobridge/go.mod
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
990 changes: 990 additions & 0 deletions gobridge/go.sum

Large diffs are not rendered by default.

139 changes: 139 additions & 0 deletions gobridge/gobridge.go
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() {}
86 changes: 86 additions & 0 deletions gobridge/gobridge.h
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
77 changes: 77 additions & 0 deletions gobridge/interface.h
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;

Loading

0 comments on commit b87f27d

Please sign in to comment.