diff --git a/desktop/lib.go b/desktop/lib.go index b7f32782a..156392c76 100644 --- a/desktop/lib.go +++ b/desktop/lib.go @@ -32,6 +32,7 @@ import ( proclient "github.com/getlantern/lantern-client/internalsdk/pro" "github.com/getlantern/lantern-client/internalsdk/protos" "github.com/getlantern/osversion" + "github.com/joho/godotenv" "google.golang.org/protobuf/encoding/protojson" ) @@ -62,15 +63,21 @@ var issueMap = map[string]string{ } //export start -func start(cfgDir, proxyAll *C.char) { +func start() { runtime.LockOSThread() // Since Go 1.6, panic prints only the stack trace of current goroutine by // default, which may not reveal the root cause. Switch to all goroutines. debug.SetTraceback("all") - flags := flashlight.ParseFlags() - flags.ConfigDir = C.GoString(cfgDir) - flags.ProxyAll, _ = strconv.ParseBool(C.GoString(proxyAll)) + // Load application configuration from .env file + err := godotenv.Load() + if err != nil { + log.Error("Error loading .env file") + } + + flags := flashlight.ParseFlags() + flags.ConfigDir = os.Getenv("LANTERN_CONFIGDIR") + flags.ProxyAll, _ = strconv.ParseBool(os.Getenv("LANTERN_PROXYALL")) cdir := configDir(&flags) diff --git a/go.mod b/go.mod index 7113fba17..ed00ebb68 100644 --- a/go.mod +++ b/go.mod @@ -219,6 +219,7 @@ require ( github.com/hashicorp/golang-lru v1.0.2 // indirect github.com/huandu/xstrings v1.4.0 // indirect github.com/jaffee/commandeer v0.6.0 // indirect + github.com/joho/godotenv v1.5.1 // indirect github.com/keighl/mandrill v0.0.0-20170605120353-1775dd4b3b41 // indirect github.com/kennygrant/sanitize v1.2.4 // indirect github.com/klauspost/compress v1.17.6 // indirect diff --git a/go.sum b/go.sum index 4c6ec51fd..bd02ec2a5 100644 --- a/go.sum +++ b/go.sum @@ -599,6 +599,8 @@ github.com/jaffee/commandeer v0.6.0 h1:YI44XLWcJN21euhh32sZW8vM/tljPYxhsXIfEPkQK github.com/jaffee/commandeer v0.6.0/go.mod h1:kCwfuSvZ2T0NVEr3LDSo6fDUgi0xSBnAVDdkOKTtpLQ= github.com/jawher/mow.cli v1.1.0/go.mod h1:aNaQlc7ozF3vw6IJ2dHjp2ZFiA4ozMIYY6PyuRJwlUg= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a/go.mod h1:Oz+70psSo5OFh8DBl0Zv2ACw7Esh6pPUphlvZG9x7uw= github.com/jsimonetti/rtnetlink v0.0.0-20200117123717-f846d4f6c1f4 h1:nwOc1YaOrYJ37sEBrtWZrdqzK22hiJs3GpDmP3sR2Yw= diff --git a/hit_proxy.bash b/hit_proxy.bash index 18fa4d19f..f7c74efcd 100755 --- a/hit_proxy.bash +++ b/hit_proxy.bash @@ -15,4 +15,4 @@ mkdir -p "$TMPDIR" echo "Generating config for ${PROXY} in ${OUTFILE}..." ../lantern-cloud/bin/ptool route dump-config --legacy "$PROXY" > "$OUTFILE" -flutter run -d macOS --dart-define="configdir=$TMPDIR" --dart-define="proxyall=true" +make darwin ffigen && LANTERN_CONFIGDIR=$TMPDIR LANTERN_PROXYALL=true flutter run -d macOS diff --git a/lib/ffi.dart b/lib/ffi.dart index a1e2e43f5..db351743a 100644 --- a/lib/ffi.dart +++ b/lib/ffi.dart @@ -197,8 +197,8 @@ final DynamicLibrary _dylib = () { /// The bindings to the native functions in [dylib]. final NativeLibrary _bindings = NativeLibrary(_dylib); -void loadLibrary(String configDir, bool proxyAll) { - _bindings.start(configDir.toPointerChar(), proxyAll.toString().toPointerChar()); +void loadLibrary() { + _bindings.start(); } //Custom exception for handling error diff --git a/lib/main.dart b/lib/main.dart index 410934174..536441e67 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -32,9 +32,7 @@ Future main() async { } if (isDesktop()) { - const configDir = String.fromEnvironment('configdir', defaultValue: ''); - const proxyAll = bool.fromEnvironment('proxyall', defaultValue: false); - loadLibrary(configDir, proxyAll); + loadLibrary(); await WebsocketImpl.instance()!.connect(); await windowManager.ensureInitialized(); WindowOptions windowOptions = const WindowOptions(