Skip to content

Commit

Permalink
feat: add web support although nothing works just as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Aug 14, 2022
1 parent d668760 commit 2818ed5
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 18 deletions.
3 changes: 1 addition & 2 deletions lib/components/Home/Home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ class Home extends HookConsumerWidget {
child: MoveWindow(),
),
Expanded(child: MoveWindow()),
if (!Platform.isMacOS && !kIsMobile)
const TitleBarActionButtons(),
if (!kIsMacOS && !kIsMobile) const TitleBarActionButtons(),
],
),
)
Expand Down
8 changes: 5 additions & 3 deletions lib/components/Player/PlayerActions.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -54,9 +55,10 @@ class PlayerActions extends HookConsumerWidget {
}
: null,
),
DownloadTrackButton(
track: playback.track,
),
if (!kIsWeb)
DownloadTrackButton(
track: playback.track,
),
if (auth.isLoggedIn)
FutureBuilder<bool>(
future: playback.track?.id != null
Expand Down
4 changes: 2 additions & 2 deletions lib/components/Shared/PageWindowTitleBar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)
],
),
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void main() async {
}
appWindow.show();
});
} else {
} else if (kIsMobile) {
await FlutterDownloader.initialize(
debug: kDebugMode,
ignoreSsl: true,
Expand Down
3 changes: 2 additions & 1 deletion lib/models/Logger.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 3 additions & 1 deletion lib/provider/DBus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<DBusClient?> dbusClientProvider = Provider<DBusClient?>((ref) {
if (Platform.isLinux) {
if (kIsLinux) {
return DBusClient.session();
}
return null;
});

final dbus = DBusClient.session();
9 changes: 5 additions & 4 deletions lib/provider/Playback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<CacheTrack>("track-cache");

if (Platform.isAndroid) {
if (kIsAndroid) {
await player.setVolume(1);
volume = 1;
} else {
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib/provider/UserPreferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -126,7 +127,7 @@ class UserPreferences extends PersistedChangeNotifier {
}

Future<String> _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");
});
Expand Down
14 changes: 11 additions & 3 deletions lib/utils/platform.dart
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 2818ed5

Please sign in to comment.