From 2818ed5c9dadb9185a52762599c1dd0acd81e6bf Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sun, 14 Aug 2022 23:03:33 +0600 Subject: [PATCH] feat: add web support although nothing works just as expected --- lib/components/Home/Home.dart | 3 +-- lib/components/Player/PlayerActions.dart | 8 +++++--- lib/components/Shared/PageWindowTitleBar.dart | 4 ++-- lib/main.dart | 2 +- lib/models/Logger.dart | 3 ++- lib/provider/DBus.dart | 4 +++- lib/provider/Playback.dart | 9 +++++---- lib/provider/UserPreferences.dart | 3 ++- lib/utils/platform.dart | 14 +++++++++++--- 9 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/components/Home/Home.dart b/lib/components/Home/Home.dart index 517d81854..39b1333af 100644 --- a/lib/components/Home/Home.dart +++ b/lib/components/Home/Home.dart @@ -90,8 +90,7 @@ class Home extends HookConsumerWidget { child: MoveWindow(), ), Expanded(child: MoveWindow()), - if (!Platform.isMacOS && !kIsMobile) - const TitleBarActionButtons(), + if (!kIsMacOS && !kIsMobile) const TitleBarActionButtons(), ], ), ) diff --git a/lib/components/Player/PlayerActions.dart b/lib/components/Player/PlayerActions.dart index 69f0797b8..ac92963d1 100644 --- a/lib/components/Player/PlayerActions.dart +++ b/lib/components/Player/PlayerActions.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:spotify/spotify.dart'; @@ -54,9 +55,10 @@ class PlayerActions extends HookConsumerWidget { } : null, ), - DownloadTrackButton( - track: playback.track, - ), + if (!kIsWeb) + DownloadTrackButton( + track: playback.track, + ), if (auth.isLoggedIn) FutureBuilder( future: playback.track?.id != null diff --git a/lib/components/Shared/PageWindowTitleBar.dart b/lib/components/Shared/PageWindowTitleBar.dart index 4579c4edf..753542044 100644 --- a/lib/components/Shared/PageWindowTitleBar.dart +++ b/lib/components/Shared/PageWindowTitleBar.dart @@ -110,13 +110,13 @@ class PageWindowTitleBar extends StatelessWidget color: backgroundColor, child: Row( children: [ - if (Platform.isMacOS) + if (kIsMacOS) SizedBox( width: MediaQuery.of(context).size.width * 0.045, ), if (leading != null) leading!, Expanded(child: MoveWindow(child: Center(child: center))), - if (!Platform.isMacOS && !kIsMobile) + if (!kIsMacOS && !kIsMobile) TitleBarActionButtons(color: foregroundColor) ], ), diff --git a/lib/main.dart b/lib/main.dart index 5709e0332..fdd3cb8a0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -46,7 +46,7 @@ void main() async { } appWindow.show(); }); - } else { + } else if (kIsMobile) { await FlutterDownloader.initialize( debug: kDebugMode, ignoreSsl: true, diff --git a/lib/models/Logger.dart b/lib/models/Logger.dart index d92994682..d0a6288cb 100644 --- a/lib/models/Logger.dart +++ b/lib/models/Logger.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:flutter/foundation.dart'; import 'package:logger/logger.dart'; import 'package:path_provider/path_provider.dart'; import 'package:path/path.dart' as path; @@ -31,7 +32,7 @@ class _SpotubeLogger extends Logger { class _SpotubeLogFilter extends DevelopmentFilter { @override bool shouldLog(LogEvent event) { - final env = Platform.environment; + final env = kIsWeb ? {} : Platform.environment; if ((env["DEBUG"] == "true" && event.level == Level.debug) || (env["VERBOSE"] == "true" && event.level == Level.verbose) || (env["ERROR"] == "true" && event.level == Level.error)) { diff --git a/lib/provider/DBus.dart b/lib/provider/DBus.dart index 627046595..bd725b735 100644 --- a/lib/provider/DBus.dart +++ b/lib/provider/DBus.dart @@ -2,11 +2,13 @@ import 'dart:io'; import 'package:dbus/dbus.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:spotube/utils/platform.dart'; final Provider dbusClientProvider = Provider((ref) { - if (Platform.isLinux) { + if (kIsLinux) { return DBusClient.session(); } + return null; }); final dbus = DBusClient.session(); diff --git a/lib/provider/Playback.dart b/lib/provider/Playback.dart index 147f569dc..14d547731 100644 --- a/lib/provider/Playback.dart +++ b/lib/provider/Playback.dart @@ -18,6 +18,7 @@ import 'package:spotube/provider/YouTube.dart'; import 'package:spotube/services/LinuxAudioService.dart'; import 'package:spotube/services/MobileAudioService.dart'; import 'package:spotube/utils/PersistedChangeNotifier.dart'; +import 'package:spotube/utils/platform.dart'; import 'package:spotube/utils/primitive_utils.dart'; import 'package:spotube/utils/service_utils.dart'; import 'package:spotube/utils/type_conversion_utils.dart'; @@ -79,14 +80,14 @@ class Playback extends PersistedChangeNotifier { _subscriptions = [], status = PlaybackStatus.idle, super() { - if (Platform.isLinux) { + if (kIsLinux) { _linuxAudioService = LinuxAudioService(this); } (() async { cache = await Hive.openLazyBox("track-cache"); - if (Platform.isAndroid) { + if (kIsAndroid) { await player.setVolume(1); volume = 1; } else { @@ -433,9 +434,9 @@ class Playback extends PersistedChangeNotifier { final audioManifest = trackManifest.audioOnly.where((info) { final isMp4a = info.codec.mimeType == "audio/mp4"; - if (Platform.isLinux) { + if (kIsLinux) { return !isMp4a; - } else if (Platform.isMacOS || Platform.isIOS) { + } else if (kIsMacOS || kIsIOS) { return isMp4a; } else { return true; diff --git a/lib/provider/UserPreferences.dart b/lib/provider/UserPreferences.dart index d49ededd3..aa84e5b34 100644 --- a/lib/provider/UserPreferences.dart +++ b/lib/provider/UserPreferences.dart @@ -10,6 +10,7 @@ import 'package:spotube/models/generated_secrets.dart'; import 'package:spotube/provider/Playback.dart'; import 'package:spotube/utils/PersistedChangeNotifier.dart'; import 'package:collection/collection.dart'; +import 'package:spotube/utils/platform.dart'; import 'package:spotube/utils/primitive_utils.dart'; import 'package:path/path.dart' as path; @@ -126,7 +127,7 @@ class UserPreferences extends PersistedChangeNotifier { } Future _getDefaultDownloadDirectory() async { - if (Platform.isAndroid) return "/storage/emulated/0/Download/Spotube"; + if (kIsAndroid) return "/storage/emulated/0/Download/Spotube"; return getDownloadsDirectory().then((dir) { return path.join(dir!.path, "Spotube"); }); diff --git a/lib/utils/platform.dart b/lib/utils/platform.dart index af70c382c..77c29fcdd 100644 --- a/lib/utils/platform.dart +++ b/lib/utils/platform.dart @@ -1,7 +1,15 @@ import 'dart:io'; -final kIsDesktop = Platform.isLinux || Platform.isWindows || Platform.isMacOS; +import 'package:flutter/foundation.dart'; -final kIsMobile = Platform.isAndroid || Platform.isIOS; +final kIsDesktop = kIsLinux || kIsWindows || kIsMacOS; -final kIsFlatpak = Platform.environment["FLATPAK_ID"] != null; +final kIsMobile = kIsAndroid || kIsIOS; + +final kIsFlatpak = kIsWeb ? false : Platform.environment["FLATPAK_ID"] != null; + +final kIsMacOS = kIsWeb ? false : Platform.isMacOS; +final kIsLinux = kIsWeb ? false : Platform.isLinux; +final kIsAndroid = kIsWeb ? false : Platform.isAndroid; +final kIsIOS = kIsWeb ? false : Platform.isIOS; +final kIsWindows = kIsWeb ? false : Platform.isWindows;