Skip to content

Commit

Permalink
fix: do not retry connect to discord, update deps (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier authored Oct 20, 2024
1 parent 4fd2980 commit 2387977
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 122 deletions.
68 changes: 42 additions & 26 deletions lib/app/view/scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_tabler_icons/flutter_tabler_icons.dart';
import 'package:watch_it/watch_it.dart';
import 'package:yaru/yaru.dart';

import '../../app_config.dart';
import '../../common/view/snackbars.dart';
import '../../common/view/theme.dart';
import '../../constants.dart';
Expand Down Expand Up @@ -44,32 +45,20 @@ class _MusicPodScaffoldState extends State<MusicPodScaffold> {
Widget build(BuildContext context) {
final playerToTheRight = context.mediaQuerySize.width > kSideBarThreshHold;
final isFullScreen = watchPropertyValue((AppModel m) => m.fullWindowMode);
final l10n = context.l10n;
registerStreamHandler(
select: (AppModel m) => m.isDiscordConnectedStream,
handler: (context, snapshot, cancel) {
if (!snapshot.hasData || snapshot.hasError) return;
showSnackBar(
context: context,
content: Row(
mainAxisSize: MainAxisSize.min,
children: space(
widthGap: 10,
children: [
Text(
'${snapshot.data == true ? l10n.connectedTo : l10n.disconnectedFrom}'
' ${l10n.exposeToDiscordTitle}',
),
Icon(
TablerIcons.brand_discord_filled,
color: context.theme.primaryColor,
),
],
),
),
);
},
);

if (allowDiscordRPC) {
registerStreamHandler(
select: (AppModel m) => m.isDiscordConnectedStream,
handler: (context, snapshot, cancel) {
if (!snapshot.hasData || snapshot.hasError) return;
showSnackBar(
context: context,
duration: const Duration(seconds: 3),
content: _DiscordConnectContent(connected: snapshot.data == true),
);
},
);
}

return Stack(
alignment: Alignment.center,
Expand Down Expand Up @@ -98,3 +87,30 @@ class _MusicPodScaffoldState extends State<MusicPodScaffold> {
);
}
}

class _DiscordConnectContent extends StatelessWidget {
const _DiscordConnectContent({required this.connected});

final bool connected;

@override
Widget build(BuildContext context) {
final l10n = context.l10n;
return Row(
mainAxisSize: MainAxisSize.min,
children: space(
widthGap: 10,
children: [
Text(
'${connected ? l10n.connectedTo : l10n.disconnectedFrom}'
' ${l10n.exposeToDiscordTitle}',
),
Icon(
TablerIcons.brand_discord_filled,
color: context.theme.primaryColor,
),
],
),
);
}
}
1 change: 1 addition & 0 deletions lib/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ import 'package:flutter/foundation.dart';
bool allowDiscordRPC = kDebugMode ||
Platform.isMacOS ||
Platform.isWindows ||
Platform.isLinux ||
bool.tryParse(const String.fromEnvironment('ALLOW_DISCORD_RPC')) == true;
6 changes: 6 additions & 0 deletions lib/common/view/icons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import 'package:yaru/yaru.dart';
import 'theme.dart';

class Iconz {
static IconData get image => yaruStyled
? YaruIcons.image
: appleStyled
? CupertinoIcons.photo
: Icons.image_not_supported;

static IconData get warning => yaruStyled
? YaruIcons.warning_filled
: appleStyled
Expand Down
9 changes: 6 additions & 3 deletions lib/expose/expose_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ExposeService {
}) async {
try {
if (_discordRPC?.isConnected == false) {
await _discordRPC?.connect(autoRetry: true);
await _discordRPC?.connect();
}
if (_discordRPC?.isConnected == true) {
await _discordRPC?.setActivity(
Expand All @@ -37,8 +37,11 @@ class ExposeService {
} on Exception catch (_) {}
}

Future<void> connectToDiscord() async =>
_discordRPC?.connect(autoRetry: true);
Future<void> connect() async {
await connectToDiscord();
}

Future<void> connectToDiscord() async => _discordRPC?.connect();

Future<void> disconnectFromDiscord() async => _discordRPC?.disconnect();

Expand Down
6 changes: 3 additions & 3 deletions lib/player/player_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,13 @@ class PlayerService {
case PressedButton.play:
playOrPause().then(
(_) => _smtc?.setPlaybackStatus(
_isPlaying ? PlaybackStatus.Playing : PlaybackStatus.Paused,
_isPlaying ? PlaybackStatus.playing : PlaybackStatus.paused,
),
);
case PressedButton.pause:
playOrPause().then(
(_) => _smtc?.setPlaybackStatus(
_isPlaying ? PlaybackStatus.Playing : PlaybackStatus.Paused,
_isPlaying ? PlaybackStatus.playing : PlaybackStatus.paused,
),
);
case PressedButton.next:
Expand Down Expand Up @@ -727,7 +727,7 @@ class PlayerService {
);
} else if (_smtc != null) {
_smtc!.setPlaybackStatus(
playing ? PlaybackStatus.Playing : PlaybackStatus.Paused,
playing ? PlaybackStatus.playing : PlaybackStatus.paused,
);
}
}
Expand Down
8 changes: 7 additions & 1 deletion lib/player/view/bottom_player_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ class BottomPlayerImage extends StatelessWidget with WatchItMixin {
padding: const EdgeInsets.only(left: 5),
child: Tooltip(
message: context.l10n.onlineArtError,
child: Icon(Iconz.warning, color: Colors.yellowAccent),
child: Icon(
Iconz.imageMissingFilled,
color: Colors.white,
shadows: [
const BoxShadow(offset: Offset(0, 1), blurRadius: 1),
],
),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/player/view/full_height_player_top_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class FullHeightPlayerTopControls extends StatelessWidget with WatchItMixin {
snackBar: SnackBar(content: Text(context.l10n.onlineArtError)),
),
icon: Icon(
Iconz.warning,
Iconz.imageMissingFilled,
color: context.theme.colorScheme.onSurface,
),
),
Expand Down
9 changes: 5 additions & 4 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ PODS:
- FlutterMacOS
- file_selector_macos (0.0.1):
- FlutterMacOS
- flutter_discord_rpc (0.0.1)
- flutter_discord_rpc (0.0.1):
- FlutterMacOS
- FlutterMacOS (1.0.0)
- irondash_engine_context (0.0.1):
- FlutterMacOS
Expand Down Expand Up @@ -119,16 +120,16 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
audio_service: b88ff778e0e3915efd4cd1a5ad6f0beef0c950a9
audio_session: dea1f41890dbf1718f04a56f1d6150fd50039b72
connectivity_plus: ddd7f30999e1faaef5967c23d5b6d503d10434db
connectivity_plus: 4c41c08fc6d7c91f63bc7aec70ffe3730b04f563
device_info_plus: ce1b7762849d3ec103d0e0517299f2db7ad60720
file_selector_macos: cc3858c981fe6889f364731200d6232dac1d812d
flutter_discord_rpc: 53b006f68ef620a99fe1b3ba7e83513f3ae95b4c
flutter_discord_rpc: 67a7c10ea24d9d3bf35d01af643f48fbcfa7c24f
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
irondash_engine_context: da62996ee25616d2f01bbeb85dc115d813359478
media_kit_libs_macos_video: b3e2bbec2eef97c285f2b1baa7963c67c753fb82
media_kit_native_event_loop: 81fd5b45192b72f8b5b69eaf5b540f45777eb8d5
media_kit_video: c75b07f14d59706c775778e4dd47dd027de8d1e5
package_info_plus: d2f71247aab4b6521434f887276093acc70d214c
package_info_plus: f5790acc797bf17c3e959e9d6cf162cc68ff7523
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
screen_brightness_macos: 2d6d3af2165592d9a55ffcd95b7550970e41ebda
screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38
Expand Down
Loading

0 comments on commit 2387977

Please sign in to comment.