Skip to content

Commit

Permalink
pass arguments with environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
atavism committed May 31, 2024
1 parent 159f738 commit d329467
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
15 changes: 11 additions & 4 deletions desktop/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion hit_proxy.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ Future<void> 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(
Expand Down

0 comments on commit d329467

Please sign in to comment.