mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-13 09:20:31 -07:00
Init repo
This commit is contained in:
commit
764b6034e3
566 changed files with 212335 additions and 0 deletions
64
lib/providers/session_info_provider.dart
Normal file
64
lib/providers/session_info_provider.dart
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:fladder/jellyfin/jellyfin_open_api.swagger.dart';
|
||||
import 'package:fladder/providers/api_provider.dart';
|
||||
import 'package:fladder/providers/user_provider.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'session_info_provider.freezed.dart';
|
||||
part 'session_info_provider.g.dart';
|
||||
|
||||
@Riverpod()
|
||||
class SessionInfo extends _$SessionInfo {
|
||||
late final api = ref.read(jellyApiProvider);
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
SessionInfoModel build() {
|
||||
ref.onDispose(() => _timer?.cancel());
|
||||
_startTimer();
|
||||
return SessionInfoModel();
|
||||
}
|
||||
|
||||
void _startTimer() {
|
||||
_fetchData();
|
||||
_timer = Timer.periodic(Duration(seconds: 2), (timer) async {
|
||||
await _fetchData();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _fetchData() async {
|
||||
final deviceId = ref.read(userProvider)?.credentials.deviceId;
|
||||
if (deviceId == null) {
|
||||
state = SessionInfoModel();
|
||||
return;
|
||||
}
|
||||
|
||||
final response = await api.sessionsInfo(deviceId);
|
||||
|
||||
final session = response.body?.firstOrNull;
|
||||
|
||||
if (session == null) {
|
||||
state = SessionInfoModel();
|
||||
return;
|
||||
}
|
||||
|
||||
state = SessionInfoModel(
|
||||
playbackModel: session.playState?.playMethod?.name,
|
||||
transCodeInfo: session.transcodingInfo,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@freezed
|
||||
class SessionInfoModel with _$SessionInfoModel {
|
||||
const SessionInfoModel._();
|
||||
|
||||
factory SessionInfoModel({
|
||||
String? playbackModel,
|
||||
TranscodingInfo? transCodeInfo,
|
||||
}) = _SessionInfoModel;
|
||||
|
||||
factory SessionInfoModel.fromJson(Map<String, dynamic> json) => _$SessionInfoModelFromJson(json);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue