Skip to content

Commit

Permalink
chore: add a better discord flag from env (#957)
Browse files Browse the repository at this point in the history
* chore: add a better discord flag from env
  • Loading branch information
Feichtmeier authored Oct 16, 2024
1 parent be1b198 commit 7ad3773
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
6 changes: 6 additions & 0 deletions lib/app_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TODO(#946): make discord work inside the snap
// or leave it for linux disabled if this won't work
import 'package:flutter/foundation.dart';

bool allowDiscordRPC = kDebugMode ||
bool.tryParse(const String.fromEnvironment('ALLOW_DISCORD_RPC')) == true;
4 changes: 0 additions & 4 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,3 @@ const kAlbumArtHeaders = {
const kAudioHeaderDescriptionWidth = 400.0;

const kShowLeadingThreshold = 3000;

// TODO(#946): make discord work inside the snap
// or leave it for linux disabled if this won't work
bool kDiscordEnabledOnPlatform = true;
5 changes: 3 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import '../../library/library_model.dart';
import 'app/app_model.dart';
import 'app/connectivity_model.dart';
import 'app/view/app.dart';
import 'app_config.dart';
import 'constants.dart';
import 'expose/expose_service.dart';
import 'library/library_service.dart';
Expand Down Expand Up @@ -59,8 +60,8 @@ Future<void> main(List<String> args) async {
final sharedPreferences = await SharedPreferences.getInstance();
final version = (await PackageInfo.fromPlatform()).version;

final enableDiscord = kDiscordEnabledOnPlatform &&
sharedPreferences.get(kEnableDiscordRPC) == true;
final enableDiscord =
allowDiscordRPC && sharedPreferences.get(kEnableDiscordRPC) == true;
if (enableDiscord) {
await FlutterDiscordRPC.initialize(kDiscordApplicationId);
FlutterDiscordRPC.instance.connect();
Expand Down
7 changes: 4 additions & 3 deletions lib/settings/view/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:yaru/yaru.dart';

import '../../app/app_model.dart';
import '../../app/connectivity_model.dart';
import '../../app_config.dart';
import '../../common/data/close_btn_action.dart';
import '../../common/view/common_widgets.dart';
import '../../common/view/drop_down_arrow.dart';
Expand Down Expand Up @@ -495,15 +496,15 @@ class _ExposeOnlineSection extends StatelessWidget with WatchItMixin {
YaruTile(
title: Text(l10n.exposeToDiscordTitle),
subtitle: Text(
kDiscordEnabledOnPlatform
allowDiscordRPC
? l10n.exposeToDiscordSubTitle
: l10n.featureDisabledOnPlatform,
),
trailing: CommonSwitch(
value: kDiscordEnabledOnPlatform
value: allowDiscordRPC
? watchPropertyValue((SettingsModel m) => m.enableDiscordRPC)
: false,
onChanged: kDiscordEnabledOnPlatform
onChanged: allowDiscordRPC
? di<SettingsModel>().setEnableDiscordRPC
: null,
),
Expand Down

0 comments on commit 7ad3773

Please sign in to comment.