diff --git a/lib/app_config.dart b/lib/app_config.dart new file mode 100644 index 000000000..0e6e7edaf --- /dev/null +++ b/lib/app_config.dart @@ -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; diff --git a/lib/constants.dart b/lib/constants.dart index 13a1f1842..741632524 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -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; diff --git a/lib/main.dart b/lib/main.dart index 3ee694cda..6ea47a0a8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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'; @@ -59,8 +60,8 @@ Future main(List 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(); diff --git a/lib/settings/view/settings_page.dart b/lib/settings/view/settings_page.dart index 9f31cdbe9..ad8be753a 100644 --- a/lib/settings/view/settings_page.dart +++ b/lib/settings/view/settings_page.dart @@ -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'; @@ -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().setEnableDiscordRPC : null, ),