Skip to content

Commit

Permalink
Merge pull request #462 from lamarios/feature/sembast
Browse files Browse the repository at this point in the history
Feature/sembast
  • Loading branch information
lamarios authored Jan 30, 2024
2 parents 8cb440e + 2c5a9f3 commit 9155463
Show file tree
Hide file tree
Showing 121 changed files with 2,783 additions and 3,455 deletions.
51 changes: 26 additions & 25 deletions lib/app/states/app.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:invidious/router.dart';
import 'package:logging/logging.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';

import '../../database.dart';
import '../../globals.dart';
import '../../home/models/db/home_layout.dart';
import '../../settings/models/db/server.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import '../../settings/models/db/settings.dart';

part 'app.freezed.dart';

Expand All @@ -19,9 +19,30 @@ class AppCubit extends Cubit<AppState> {
late final StreamSubscription intentDataStreamSubscription;
AppCubit(super.initialState) {
onReady();
initState();
}

initState() async {
Server? server;
try {
server = await db.getCurrentlySelectedServer();
} catch (e) {
server = null;
}
HomeLayout homeLayout = db.getHomeLayout();
bool isLoggedIn = (server?.authToken?.isNotEmpty ?? false) ||
(server?.sidCookie?.isNotEmpty ?? false);

var selectedIndex =
int.parse(db.getSettings(onOpenSettingName)?.value ?? '0');
if (!isLoggedIn && selectedIndex > 1 || selectedIndex < 0) {
selectedIndex = 0;
}
emit(state.copyWith(
selectedIndex: selectedIndex, homeLayout: homeLayout, server: server));
}

onReady() {
onReady() async {
intentDataStreamSubscription =
ReceiveSharingIntent.getTextStream().listen((String value) {
openAppLink(value);
Expand Down Expand Up @@ -87,26 +108,6 @@ class AppCubit extends Cubit<AppState> {

@freezed
class AppState with _$AppState {
static AppState init() {
late Server? server;
try {
server = db.getCurrentlySelectedServer();
} catch (e) {
server = null;
}
HomeLayout homeLayout = db.getHomeLayout();
bool isLoggedIn = (server?.authToken?.isNotEmpty ?? false) ||
(server?.sidCookie?.isNotEmpty ?? false);

var selectedIndex =
int.parse(db.getSettings(onOpenSettingName)?.value ?? '0');
if (!isLoggedIn && selectedIndex > 1 || selectedIndex < 0) {
selectedIndex = 0;
}

return AppState(selectedIndex, server, homeLayout);
}

factory AppState(int selectedIndex, Server? server, HomeLayout homeLayout) =
_AppState;
const factory AppState(
int selectedIndex, Server? server, HomeLayout homeLayout) = _AppState;
}
4 changes: 2 additions & 2 deletions lib/app/states/app.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class __$$AppStateImplCopyWithImpl<$Res>
/// @nodoc
class _$AppStateImpl implements _AppState {
_$AppStateImpl(this.selectedIndex, this.server, this.homeLayout);
const _$AppStateImpl(this.selectedIndex, this.server, this.homeLayout);

@override
final int selectedIndex;
Expand Down Expand Up @@ -151,7 +151,7 @@ class _$AppStateImpl implements _AppState {
}

abstract class _AppState implements AppState {
factory _AppState(final int selectedIndex, final Server? server,
const factory _AppState(final int selectedIndex, final Server? server,
final HomeLayout homeLayout) = _$AppStateImpl;

@override
Expand Down
4 changes: 3 additions & 1 deletion lib/app/views/tv/screens/tv_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ class TvHomeScreen extends StatelessWidget {
var homeCubit = context.read<TvHomeCubit>();
var appLayout =
context.select((SettingsCubit value) => value.state.appLayout);
var isLoggedIn =
context.select((AppCubit value) => value.isLoggedIn);
var allowedPages = appLayout
.where((element) => element.isPermitted(context))
.where((element) => element.isPermitted(context, isLoggedIn))
.toList();
return BlocBuilder<AppCubit, AppState>(
buildWhen: (previous, current) {
Expand Down
Loading

0 comments on commit 9155463

Please sign in to comment.