Skip to content

Stage env#8401

Open
jigar-f wants to merge 31 commits intomainfrom
jigar/stage-env
Open

Stage env#8401
jigar-f wants to merge 31 commits intomainfrom
jigar/stage-env

Conversation

@jigar-f
Copy link
Contributor

@jigar-f jigar-f commented Jan 7, 2026

This pull request introduces environment awareness to the application, allowing it to distinguish between "production" and "staging" modes across Android, iOS, and Flutter. The environment can now be toggled from the developer settings, and this state is persisted and communicated to native code at startup. The changes span native code, Flutter models, database schema, and developer UI.

Environment Detection and Propagation:

  • Added logic to detect the environment (prod/stage) at startup on both Android (getRadianceEnv() in utils.kt) and iOS (isRadianceEnv() in FilePath.swift), based on the presence of a .radiance_env file. This value is passed to the core initialization so that the backend can behave accordingly. [1] [2] [3] [4] [5] [6]

  • The .radiance_env file is now written from Flutter using a new utility method, ensuring native code can read the correct environment before Flutter is ready.

Flutter Model and Database Updates:

Developer UI Enhancements:

  • Added a "Stage Environment" switch to the developer mode screen (except on iOS), allowing toggling between environments. The user is prompted to restart the app for changes to take effect. [1] [2] [3]

  • Refactored the developer mode UI to group tiles more logically and moved "Reset App" to its own card. [1] [2]

Core and Build System Changes:

  • Updated the Go core and FFI layer to accept and propagate the environment option, and set the correct environment before initializing Radiance. [1] [2] [3] [4]

  • Minor: Updated the radiance dependency version and made a small Makefile change to echo the current environment during macOS framework builds. [1] [2] [3]

These changes collectively enable robust environment switching and awareness across the app stack, facilitating easier testing and deployment.

@jigar-f
Copy link
Contributor Author

jigar-f commented Jan 7, 2026

@atavism Any Idea here, Why macos step is skipping without error?

@jigar-f
Copy link
Contributor Author

jigar-f commented Jan 7, 2026

Found the issue.

@jigar-f jigar-f self-assigned this Jan 8, 2026
@jigar-f
Copy link
Contributor Author

jigar-f commented Jan 8, 2026

@atavism Feel free to take this one this sprint, if you have time.

@atavism
Copy link
Contributor

atavism commented Jan 15, 2026

@jigar-f Will do so today!

@atavism
Copy link
Contributor

atavism commented Jan 23, 2026

@jigar-f Is this one still a draft, or is ready for review now @jigar-f?

@jigar-f
Copy link
Contributor Author

jigar-f commented Jan 23, 2026

@atavism this is not even complete. Feel free to take it if you have a time.

@jigar-f jigar-f marked this pull request as ready for review February 13, 2026 11:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds environment awareness to the Lantern application, enabling it to distinguish between "production" and "staging" modes across all platforms (Android, iOS, macOS, and via FFI). The environment can be toggled from developer settings on most platforms, with the state persisted locally and communicated to native code at startup.

Changes:

  • Added environment detection and propagation from Flutter through native code (iOS/macOS/Android) to the Go core backend
  • Updated database schema to persist environment setting in AppSetting entity
  • Added UI toggle in developer settings to switch environments (excluded from iOS) with app restart prompt
  • Modified macOS to use a shared directory (/Users/Shared/Lantern) instead of user-specific Application Support

Reviewed changes

Copilot reviewed 37 out of 49 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
macos/Shared/FilePath.swift Changed app support directory to shared location and added environment detection
macos/Runner/Handlers/MethodHandler.swift Updated plans method to accept channel parameter
macos/Runner/AppDelegate.swift Added environment setting to initialization options
macos/Podfile.lock Updated pod checksums from dependency changes
lib/lantern/lantern_ffi_service.dart Added environment parameter to FFI setup call
lib/features/home/provider/app_setting_notifier.dart Implemented setEnvironment method with directory cleanup
lib/features/developer/developer_mode.dart Added environment toggle UI (excluded from iOS)
lib/core/utils/storage_utils.dart Added writeRadianceEnvFile utility method
lib/core/services/db/objectbox.g.dart Generated code for new environment field
lib/core/services/db/objectbox-model.json Updated schema with environment property
lib/core/models/entity/app_setting_entity.dart Added environment field to AppSetting entity
lantern-core/utils/common.go Added Env field to Opts struct
lantern-core/ffi/ffi.go Added _env parameter to setup function
lantern-core/core.go Added logic to set environment before Radiance initialization
ios/Shared/FilePath.swift Added isRadianceEnv method for environment detection
ios/Runner/AppDelegate.swift Added environment setting to initialization options
go.mod Updated radiance dependency and uncommented replace directive
go.sum Updated checksums for radiance dependency
android/app/src/main/kotlin/.../utils.kt Added getRadianceEnv function
android/app/src/main/kotlin/.../LanternVpnService.kt Added environment to VPN service options
Makefile Added echo for RADIANCE_ENV during macOS build
.github/workflows/nightly.yml Removed trailing whitespace
.github/workflows/build-macos.yml Removed trailing whitespace
Comments suppressed due to low confidence (3)

lib/features/home/provider/app_setting_notifier.dart:149

  • The logic for switching to production mode (when isStaging is false) contains redundant file deletion. Lines 146-149 attempt to delete the .radiance_env file, but the entire directory has already been deleted recursively on line 140. The file deletion check and operation at lines 146-149 will never find a file since the directory was just recreated empty on line 144.
    go.mod:5
  • The replace directive for github.com/getlantern/radiance is uncommented, pointing to a local ../radiance directory. This is typically used for local development and should not be committed to the repository for production releases. This will cause build failures for anyone who doesn't have the radiance repository checked out in the expected relative location. Consider removing this replace directive or commenting it out before merging.
// replace github.com/getlantern/radiance => ../radiance

lib/features/home/provider/app_setting_notifier.dart:150

  • The setEnvironment method deletes the entire app directory recursively (line 127 and 140), which will delete all user data including user accounts, settings, VPN configurations, and any other data stored in that directory. This is a destructive operation that goes beyond just switching environments. Users will lose their login session, preferences, and other important data.

Consider either:

  1. Documenting this behavior clearly in the UI to warn users
  2. Selectively preserving important user data that shouldn't be lost on environment switch
  3. Only deleting radiance-specific data that needs to be cleared for environment changes

The current implementation treats environment switching like a full app reset, which may not be the intended behavior.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 48 to 57
private static func appSupportDir() -> URL {
let base = FileManager.default
.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
let dir = URL(fileURLWithPath: "/Users/Shared/Lantern", isDirectory: true)

// Create directory if it doesn't exist
try? FileManager.default.createDirectory(
at: dir,
withIntermediateDirectories: true,
attributes: nil)

let bundleId = FilePath.bundleId
let dir = base.appendingPathComponent(bundleId, isDirectory: true)
return dir
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change hardcodes the application data directory to "/Users/Shared/Lantern", which is a significant change from the previous implementation that used the user's Application Support directory. This has several implications:

  1. All users on the system will share the same Lantern data, including VPN settings, user accounts, and environment configuration
  2. This may cause privacy concerns as one user's data becomes accessible to other users
  3. The /Users/Shared directory requires appropriate permissions and may not be accessible in all environments
  4. This breaks data isolation between different user accounts

This appears to be an intentional change based on the PR context, but it's a breaking change that could affect existing users. Consider documenting this change and providing a migration path for existing user data.

Copilot uses AI. Check for mistakes.
guard let channel: String = self.decodeValue(from: call.arguments, result: result) else {
return
}
self.plans(result: result, channel: channel)
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent formatting: there's a missing space after the comma in the plans method call. Line 48 has "result,channel:" which should be "result, channel:" to match Swift formatting conventions and the rest of the codebase.

Copilot uses AI. Check for mistakes.

$(MACOS_FRAMEWORK_BUILD): $(GO_SOURCES)
@echo "Building macOS Framework.."
echo "RADIANCE_ENV $(RADIANCE_ENV)"
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The echo statement on line 177 is missing a dollar sign before the variable name. It should be "echo "RADIANCE_ENV $$RADIANCE_ENV"" or "echo "RADIANCE_ENV $(RADIANCE_ENV)"" to actually print the value of the RADIANCE_ENV variable. Currently it will just print the literal string "RADIANCE_ENV $(RADIANCE_ENV)" without expanding the variable.

Suggested change
echo "RADIANCE_ENV $(RADIANCE_ENV)"
echo "RADIANCE_ENV $$RADIANCE_ENV"

Copilot uses AI. Check for mistakes.
},
),
),
DividerSpace(),
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a DividerSpace on line 82 that will always render, even when "Test Play Purchase" is not shown (on non-Android platforms). This will create an extra divider at the top of the card when the first tile is "Stage Environment". Consider wrapping the DividerSpace in the same conditional as the "Test Play Purchase" tile, or moving it inside that conditional block.

Suggested change
DividerSpace(),
if (PlatformUtils.isAndroid)
DividerSpace(),

Copilot uses AI. Check for mistakes.
Comment on lines +119 to +135
Future<void> setEnvironment(bool isStaging) async {
update(state.copyWith(environment: isStaging ? 'staging' : 'production'));

final dir = await AppStorageUtils.getAppDirectory();

// Delete and recreate the directory
if (dir.existsSync()) {
await dir.delete(recursive: true);
}
await dir.create(recursive: true);

// Create .radiance_env file only in staging
if (isStaging) {
final file = File('${dir.path}/.radiance_env');
await file.create();
}
}
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a semantic mismatch in how the environment is stored vs read. Flutter's setEnvironment stores the string 'staging' or 'production' in the AppSetting model, but the .radiance_env file is created/deleted without any content. The native code (iOS, macOS, Android) only checks for file existence, not the content. This works but is inconsistent with the writeRadianceEnvFile utility which expects to write the environment string to the file. Consider either:

  1. Writing the environment value ('stage' or 'prod') to the file content, or
  2. Removing the env parameter from writeRadianceEnvFile since only file existence matters

This inconsistency could lead to confusion in future maintenance.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants