Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Update the endpoint in configuration

vishnukvmd3593ee49310f
diff --git a/auth/lib/core/configuration.dart b/auth/lib/core/configuration.dart
index 3e6540af65..da3ad9ebf8 100644
--- a/auth/lib/core/configuration.dart
+++ b/auth/lib/core/configuration.dart
@@ -6,6 +6,7 @@ import 'dart:typed_data';
import 'package:bip39/bip39.dart' as bip39;
import 'package:ente_auth/core/constants.dart';
import 'package:ente_auth/core/event_bus.dart';
+import 'package:ente_auth/events/endpoint_updated_event.dart';
import 'package:ente_auth/events/signed_in_event.dart';
import 'package:ente_auth/events/signed_out_event.dart';
import 'package:ente_auth/models/key_attributes.dart';
@@ -42,6 +43,7 @@ class Configuration {
static const userIDKey = "user_id";
static const hasMigratedSecureStorageKey = "has_migrated_secure_storage";
static const hasOptedForOfflineModeKey = "has_opted_for_offline_mode";
+ static const endPointKey = "endpoint";
final List<String> onlineSecureKeys = [
keyKey,
secretKeyKey,
@@ -317,7 +319,12 @@ class Configuration {
}
String getHttpEndpoint() {
- return endpoint;
+ return _preferences.getString(endPointKey) ?? endpoint;
+ }
+
+ Future<void> setHttpEndpoint(String endpoint) async {
+ await _preferences.setString(endPointKey, endpoint);
+ Bus.instance.fire(EndpointUpdatedEvent());
}
String? getToken() {
diff --git a/auth/lib/events/endpoint_updated_event.dart b/auth/lib/events/endpoint_updated_event.dart
new file mode 100644
index 0000000000..0a9915479a
--- /dev/null
+++ b/auth/lib/events/endpoint_updated_event.dart
@@ -0,0 +1,3 @@
+import 'package:ente_auth/events/event.dart';
+
+class EndpointUpdatedEvent extends Event {}
diff --git a/auth/lib/l10n/arb/app_en.arb b/auth/lib/l10n/arb/app_en.arb
index 66f2b2fdf6..e3037fee43 100644
--- a/auth/lib/l10n/arb/app_en.arb
+++ b/auth/lib/l10n/arb/app_en.arb
@@ -413,5 +413,6 @@
"developerModeWarning":"Are you sure that you want to modify Developer settings?",
"developerSettings": "Developer settings",
"invalidURL": "Invalid URL",
- "invalidURLMessage": "Sorry, the URL you entered is invalid. Please enter a valid URL and try again."
+ "invalidURLMessage": "Sorry, the URL you entered is invalid. Please enter a valid URL and try again.",
+ "endpointUpdatedMessage": "Endpoint updated successfully"
}
\ No newline at end of file
diff --git a/auth/lib/ui/settings/developer_settings_page.dart b/auth/lib/ui/settings/developer_settings_page.dart
index 9efe113d15..0b11a30c13 100644
--- a/auth/lib/ui/settings/developer_settings_page.dart
+++ b/auth/lib/ui/settings/developer_settings_page.dart
@@ -1,6 +1,8 @@
+import 'package:ente_auth/core/configuration.dart';
import 'package:ente_auth/l10n/l10n.dart';
import 'package:ente_auth/ui/common/gradient_button.dart';
import 'package:ente_auth/utils/dialog_util.dart';
+import 'package:ente_auth/utils/toast_util.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
@@ -23,6 +25,9 @@ class _DeveloperSettingsPageState extends State<DeveloperSettingsPage> {
@override
Widget build(BuildContext context) {
+ _logger.info(
+ "Current endpoint is: " + Configuration.instance.getHttpEndpoint(),
+ );
return Scaffold(
appBar: AppBar(
title: Text(context.l10n.developerSettings),
@@ -33,22 +38,23 @@ class _DeveloperSettingsPageState extends State<DeveloperSettingsPage> {
children: [
TextField(
controller: _urlController,
- decoration: const InputDecoration(
+ decoration: InputDecoration(
labelText: 'Server Endpoint',
- hintText: 'https://api.ente.io:443',
+ hintText: Configuration.instance.getHttpEndpoint(),
),
autofocus: true,
),
const SizedBox(height: 40),
GradientButton(
- onTap: () {
+ onTap: () async {
String url = _urlController.text;
_logger.info("Entered endpoint: " + url);
try {
final uri = Uri.parse(url);
- if ((uri.scheme == "http" || uri.scheme == "https") &&
- (uri.hasPort || !uri.hasPort)) {
- // TODO: Save the URL
+ if ((uri.scheme == "http" || uri.scheme == "https")) {
+ await Configuration.instance.setHttpEndpoint(url);
+ showToast(context, context.l10n.endpointUpdatedMessage);
+ Navigator.of(context).pop();
} else {
throw const FormatException();
}