Compare commits

..
9 Commits
7 changed files with 71 additions and 17 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
cask "plezy" do
version "1.31.0"
sha256 "5f954b9ae041d04f49055fdc6f55c163217544302a7de5559b66ad425334fc78"
version "1.31.2"
sha256 "9d2e403ff8a0449318deab16fe1232accc3959731bb44464dc4609e80a1c04f8"
url "https://github.com/edde746/plezy/releases/download/#{version}/plezy-macos.dmg"
name "Plezy"
+2 -2
View File
@@ -18,7 +18,7 @@ PODS:
- package_info_plus (0.4.5):
- Flutter
- Sentry/HybridSDK (8.58.0)
- sentry_flutter (9.15.0):
- sentry_flutter (9.16.0):
- Flutter
- FlutterMacOS
- Sentry/HybridSDK (= 8.58.0)
@@ -128,7 +128,7 @@ SPEC CHECKSUMS:
os_media_controls: 86dceab6245a5325af90fc0fdebe243c42d789b4
package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499
Sentry: d587a8fe91ca13503ecd69a1905f3e8a0fcf61be
sentry_flutter: 8939e491bc1511868118c96cae47d945e6f69798
sentry_flutter: 31101687061fb85211ebab09ce6eb8db4e9ba74f
shared_preferences_foundation: 7036424c3d8ec98dfe75ff1667cb0cd531ec82bb
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
sqlite3: a51c07cf16e023d6c48abd5e5791a61a47354921
+4 -3
View File
@@ -396,9 +396,10 @@ class _MainAppState extends State<MainApp> with WidgetsBindingObserver {
}
case AppLifecycleState.paused:
case AppLifecycleState.detached:
if (Platform.isAndroid || Platform.isIOS) {
unawaited(_appDatabase.close());
}
// Database is session-scoped and must survive suspend/resume.
// Closing here would kill the Drift isolate channel while services
// (sync, downloads, cache) still hold references to the executor.
// SQLite WAL mode handles process death; desktop uses onExitRequested.
InAppReviewService.instance.endSession();
if (Platform.isWindows || Platform.isMacOS || Platform.isLinux) {
if (ProcessInfo.currentRss > 1024 * 1024 * 1024) { // 1GB
@@ -25,6 +25,7 @@ class OfflineWatchSyncService extends ChangeNotifier {
VoidCallback? _offlineModeListener;
bool _isSyncing = false;
bool _isBidirectionalSyncing = false;
bool _isShutDown = false;
DateTime? _lastSyncTime;
bool _hasPerformedStartupSync = false;
@@ -82,6 +83,8 @@ class OfflineWatchSyncService extends ChangeNotifier {
///
/// Push always happens immediately. Pull respects [minSyncInterval] unless [force] is true.
Future<void> _performBidirectionalSync({bool force = false}) async {
if (_isShutDown) return;
// Prevent overlapping bidirectional syncs
if (_isBidirectionalSyncing) {
appLogger.d('Bidirectional sync already in progress, skipping');
@@ -121,6 +124,7 @@ class OfflineWatchSyncService extends ChangeNotifier {
/// On mobile, always syncs immediately (device-switching scenario).
/// On desktop, respects the throttle interval.
void onAppResumed() {
if (_isShutDown) return;
if (_offlineModeProvider?.isOffline != true) {
final isMobile = Platform.isIOS || Platform.isAndroid;
appLogger.d('App resumed - ${isMobile ? "forcing" : "checking"} sync');
@@ -133,6 +137,7 @@ class OfflineWatchSyncService extends ChangeNotifier {
/// Triggers the initial sync now that PlexClients are available.
/// Only runs once per app session.
void onServersConnected() {
if (_isShutDown) return;
if (_hasPerformedStartupSync) return;
_hasPerformedStartupSync = true;
@@ -558,6 +563,7 @@ class OfflineWatchSyncService extends ChangeNotifier {
@override
void dispose() {
_isShutDown = true;
if (_offlineModeProvider != null && _offlineModeListener != null) {
_offlineModeProvider!.removeListener(_offlineModeListener!);
}
+8 -7
View File
@@ -721,7 +721,7 @@ class PlexServer {
);
if (!result.success) {
appLogger.w('HTTPS upgrade failed, staying on HTTP candidate', error: {'url': currentUrl});
appLogger.w('HTTPS upgrade failed, staying on HTTP candidate', error: {'url': currentUrl, 'reason': result.error});
return null;
}
@@ -795,18 +795,19 @@ class PlexServer {
) {
if (entries.isEmpty) return null;
// Sort by latency first, then by protocol (HTTPS > HTTP), then by URL type (prefer plex.direct)
// Sort by protocol first (HTTPS enables H2 multiplexing), then latency, then URL type
entries.sort((a, b) {
final latencyCompare = a.value.latencyMs.compareTo(b.value.latencyMs);
if (latencyCompare != 0) return latencyCompare;
// If latencies are equal, prefer HTTPS over HTTP
// Prefer HTTPS over HTTP
final aIsHttps = a.key.isHttps;
final bIsHttps = b.key.isHttps;
if (aIsHttps && !bIsHttps) return -1;
if (!aIsHttps && bIsHttps) return 1;
// If latencies and protocols are equal, prefer plex.direct URI (isPlexDirectUri = true)
// Within same protocol, sort by latency
final latencyCompare = a.value.latencyMs.compareTo(b.value.latencyMs);
if (latencyCompare != 0) return latencyCompare;
// Prefer plex.direct URI on tie
if (a.key.isPlexDirectUri && !b.key.isPlexDirectUri) return -1;
if (!a.key.isPlexDirectUri && b.key.isPlexDirectUri) return 1;
return 0;
+48 -2
View File
@@ -1,14 +1,60 @@
import 'dart:io';
import 'dart:typed_data';
import 'package:dio/dio.dart';
import 'package:dio/io.dart';
import 'package:dio_http2_adapter/dio_http2_adapter.dart';
import 'app_logger.dart';
/// Shared HTTP/2 connection pool. All Dio instances that go through
/// [createHttp2Adapter] reuse the same pool, so connections to the same
/// host are multiplexed instead of duplicated.
final _connectionManager = ConnectionManager(idleTimeout: const Duration(seconds: 15));
final _http1Fallback = IOHttpClientAdapter();
/// Returns an [Http2Adapter] backed by the shared connection pool.
HttpClientAdapter createHttp2Adapter() => Http2Adapter(_connectionManager);
/// Returns an [HttpClientAdapter] that tries HTTP/2 first and falls back
/// to HTTP/1.1 when the server rejects h2 ALPN negotiation.
HttpClientAdapter createHttp2Adapter() => _Http2WithFallbackAdapter(Http2Adapter(_connectionManager));
/// Shared [Dio] instance for ad-hoc HTTP requests that don't go through
/// [PlexClient]. Reuses the global HTTP/2 connection pool.
final httpClient = Dio()..httpClientAdapter = createHttp2Adapter();
class _Http2WithFallbackAdapter implements HttpClientAdapter {
_Http2WithFallbackAdapter(this._h2);
final Http2Adapter _h2;
static final _http1Hosts = <String>{'plex.tv'};
@override
Future<ResponseBody> fetch(
RequestOptions options,
Stream<Uint8List>? requestStream,
Future<void>? cancelFuture,
) async {
if (_http1Hosts.contains(options.uri.host)) {
return _http1Fallback.fetch(options, requestStream, cancelFuture);
}
try {
return await _h2.fetch(options, requestStream, cancelFuture);
} on HandshakeException {
appLogger.d('H2 handshake failed for ${options.uri.host}, falling back to HTTP/1.1');
_http1Hosts.add(options.uri.host);
return _http1Fallback.fetch(options, requestStream, cancelFuture);
} catch (e) {
if (e.toString().contains('HTTP/2')) {
appLogger.d('H2 connection error for ${options.uri.host}, falling back to HTTP/1.1');
_http1Hosts.add(options.uri.host);
return _http1Fallback.fetch(options, requestStream, cancelFuture);
}
rethrow;
}
}
@override
void close({bool force = false}) {
_h2.close(force: force);
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
name: plezy
description: "A beautiful Plex client for Flutter"
publish_to: "none"
version: 1.31.1+64
version: 1.31.3+67
environment:
sdk: ^3.8.1