Browse Source

feat(neon): Use window location for login on web

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/372/head
jld3103 1 year ago
parent
commit
aded2e89ca
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 5
      packages/neon/neon/lib/src/platform/android.dart
  2. 3
      packages/neon/neon/lib/src/platform/linux.dart
  3. 2
      packages/neon/neon/lib/src/platform/platform.dart
  4. 4
      packages/neon/neon/lib/src/platform/web.dart
  5. 8
      packages/neon/neon/lib/src/router.dart
  6. 1
      packages/neon/neon/pubspec.yaml

5
packages/neon/neon/lib/src/platform/android.dart

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:meta/meta.dart';
import 'package:neon/src/platform/platform.dart';
import 'package:neon/src/utils/exceptions.dart';
@ -43,6 +45,9 @@ class AndroidNeonPlatform implements NeonPlatform {
return p.join((await getExternalStorageDirectory())!.path);
}
@override
String? getWindowLocation() => null;
@override
void init() {}
}

3
packages/neon/neon/lib/src/platform/linux.dart

@ -36,6 +36,9 @@ class LinuxNeonPlatform implements NeonPlatform {
@override
String get userAccessibleAppDataPath => p.join(Platform.environment['HOME']!, 'Neon');
@override
String? getWindowLocation() => null;
@override
void init() {
sqfliteFfiInit();

2
packages/neon/neon/lib/src/platform/platform.dart

@ -69,5 +69,7 @@ abstract interface class NeonPlatform {
FutureOr<String?> get userAccessibleAppDataPath;
String? getWindowLocation();
FutureOr<void> init();
}

4
packages/neon/neon/lib/src/platform/web.dart

@ -4,6 +4,7 @@ import 'package:meta/meta.dart';
import 'package:neon/src/platform/platform.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:sqflite_common_ffi_web/sqflite_ffi_web.dart';
import 'package:universal_html/html.dart' as html;
@immutable
@internal
@ -37,6 +38,9 @@ class WebNeonPlatform implements NeonPlatform {
@override
FutureOr<String>? get userAccessibleAppDataPath => null;
@override
String getWindowLocation() => html.window.location.href;
@override
FutureOr<void> init() {
databaseFactory = databaseFactoryFfiWeb;

8
packages/neon/neon/lib/src/router.dart

@ -19,6 +19,7 @@ import 'package:neon/src/pages/login_qr_code.dart';
import 'package:neon/src/pages/nextcloud_app_settings.dart';
import 'package:neon/src/pages/route_not_found.dart';
import 'package:neon/src/pages/settings.dart';
import 'package:neon/src/platform/platform.dart';
import 'package:neon/src/utils/provider.dart';
import 'package:neon/src/utils/stream_listenable.dart';
@ -54,6 +55,13 @@ GoRouter buildAppRouter({
// redirect to login screen when no account is logged in
if (!accountsBloc.hasAccounts && !state.uri.toString().startsWith(const LoginRoute().location)) {
final windowLocation = NeonProvider.of<NeonPlatform>(context).getWindowLocation();
if (windowLocation != null) {
var uri = Uri.parse(windowLocation).removeFragment();
uri = uri.replace(path: uri.path.replaceFirst(RegExp(r'/$', multiLine: true), ''));
return LoginCheckServerStatusRoute(serverUrl: uri).location;
}
return const LoginRoute().location;
}

1
packages/neon/neon/pubspec.yaml

@ -52,6 +52,7 @@ dependencies:
tray_manager: ^0.2.0
unifiedpush: ^5.0.0
unifiedpush_android: ^2.0.0
universal_html: ^2.0.0
universal_io: ^2.0.0
url_launcher: ^6.1.0
vector_graphics: ^1.0.0

Loading…
Cancel
Save