Skip to content

Commit

Permalink
Merge pull request #730 from Komodo5197/desktop-beta-dispose
Browse files Browse the repository at this point in the history
[Desktop Beta] Windows media-kit fixes
  • Loading branch information
Chaphasilor authored May 16, 2024
2 parents c03dd22 + 4da9237 commit 96c73ff
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 135 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
push:

# Due to a flutter bug, flutter build is not generating localizations
# workaround by always running flutter pub get immediately before building,
# and performing build for msix:create manually to allow implementing this workaround
jobs:
build-android:
name: Build for Android
Expand Down Expand Up @@ -53,7 +56,6 @@ jobs:
channel: 'stable'
- run: flutter doctor
- run: flutter pub get
- run: flutter gen-l10n
# - run: flutter test
- run: flutter build linux --release --no-pub
- run: |
Expand Down Expand Up @@ -87,13 +89,12 @@ jobs:
channel: 'stable'
- run: flutter doctor
- run: flutter pub get
- run: flutter gen-l10n
# - run: flutter test
- run: flutter build windows
# TODO pack in redistributables?
- uses: actions/upload-artifact@v4
with:
name: finamp-windows-zip
name: finamp-windows
path: build/windows/x64/runner/Release/
- run: dart run msix:create --install-certificate false
#TODO would be nice to have an old-school installer here that can take the .exe + libraries and install them to the device + create a shortcut
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Future<void> showPlaylistActionsMenu({
),
),
sliver: MenuMask(
height: 45.0,
height: 36.0,
child: SliverList(
delegate: SliverChildListDelegate.fixed(
menuEntries,
Expand Down
154 changes: 81 additions & 73 deletions lib/components/AlbumScreen/song_list_tile.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'dart:async';

import 'package:audio_service/audio_service.dart';
import 'package:collection/collection.dart';
import 'package:Finamp/components/AlbumScreen/song_menu.dart';
import 'package:Finamp/components/MusicScreen/music_screen_tab_view.dart';
import 'package:Finamp/components/global_snackbar.dart';
import 'package:Finamp/models/finamp_models.dart';
import 'package:Finamp/models/jellyfin_models.dart' as jellyfin_models;
import 'package:Finamp/services/finamp_user_helper.dart';
import 'package:Finamp/services/queue_service.dart';
import 'package:audio_service/audio_service.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand Down Expand Up @@ -223,6 +223,85 @@ class _SongListTileState extends ConsumerState<SongListTile>
),
],
),
// This must be in ListTile instead of parent GestureDetecter to
// enable hover color changes
onTap: () async {
if (!playable) return;
var children = await widget.children;
if (children != null) {
// start linear playback of album from the given index
await _queueService.startPlayback(
items: children,
startingIndex: await widget.index,
order: FinampPlaybackOrder.linear,
source: QueueItemSource(
type: widget.isInPlaylist
? QueueItemSourceType.playlist
: widget.isOnArtistScreen
? QueueItemSourceType.artist
: QueueItemSourceType.album,
name: QueueItemSourceName(
type: QueueItemSourceNameType.preTranslated,
pretranslatedName: ((widget.isInPlaylist ||
widget.isOnArtistScreen)
? widget.parentItem?.name
: widget.item.album) ??
AppLocalizations.of(context)!.placeholderSource),
id: widget.parentItem?.id ?? "",
item: widget.parentItem,
// we're playing from an album, so we should use the album's normalization gain.
contextNormalizationGain:
(widget.isInPlaylist || widget.isOnArtistScreen)
? null
: widget.parentItem?.normalizationGain,
),
);
} else {
// TODO put in a real offline songs implementation
if (FinampSettingsHelper.finampSettings.isOffline) {
final settings = FinampSettingsHelper.finampSettings;
final downloadService = GetIt.instance<DownloadsService>();
final finampUserHelper = GetIt.instance<FinampUserHelper>();

// get all downloaded songs in order
List<DownloadStub> offlineItems;
// If we're on the songs tab, just get all of the downloaded items
offlineItems = await downloadService.getAllSongs(
// nameFilter: widget.searchTerm,
viewFilter: finampUserHelper.currentUser?.currentView?.id,
nullableViewFilters:
settings.showDownloadsWithUnknownLibrary);

var items = offlineItems
.map((e) => e.baseItem)
.whereNotNull()
.toList();

items = sortItems(
items,
settings.tabSortBy[TabContentType.songs],
settings.tabSortOrder[TabContentType.songs]);

await _queueService.startPlayback(
items: items,
startingIndex: widget.isShownInSearch
? items.indexWhere(
(element) => element.id == widget.item.id)
: await widget.index,
source: QueueItemSource(
name: QueueItemSourceName(
type: QueueItemSourceNameType.preTranslated,
pretranslatedName:
AppLocalizations.of(context)!.placeholderSource),
type: QueueItemSourceType.allSongs,
id: widget.item.id,
),
);
} else {
await _audioServiceHelper.startInstantMixForItem(widget.item);
}
}
},
);
});

Expand All @@ -247,77 +326,6 @@ class _SongListTileState extends ConsumerState<SongListTile>
},
onLongPressStart: (details) => menuCallback(),
onSecondaryTapDown: (details) => menuCallback(),
onTap: () async {
if (!playable) return;
var children = await widget.children;
if (children != null) {
// start linear playback of album from the given index
await _queueService.startPlayback(
items: children,
startingIndex: await widget.index,
order: FinampPlaybackOrder.linear,
source: QueueItemSource(
type: widget.isInPlaylist
? QueueItemSourceType.playlist
: widget.isOnArtistScreen
? QueueItemSourceType.artist
: QueueItemSourceType.album,
name: QueueItemSourceName(
type: QueueItemSourceNameType.preTranslated,
pretranslatedName:
((widget.isInPlaylist || widget.isOnArtistScreen)
? widget.parentItem?.name
: widget.item.album) ??
AppLocalizations.of(context)!.placeholderSource),
id: widget.parentItem?.id ?? "",
item: widget.parentItem,
// we're playing from an album, so we should use the album's normalization gain.
contextNormalizationGain:
(widget.isInPlaylist || widget.isOnArtistScreen)
? null
: widget.parentItem?.normalizationGain,
),
);
} else {
// TODO put in a real offline songs implementation
if (FinampSettingsHelper.finampSettings.isOffline) {
final settings = FinampSettingsHelper.finampSettings;
final downloadService = GetIt.instance<DownloadsService>();
final finampUserHelper = GetIt.instance<FinampUserHelper>();

// get all downloaded songs in order
List<DownloadStub> offlineItems;
// If we're on the songs tab, just get all of the downloaded items
offlineItems = await downloadService.getAllSongs(
// nameFilter: widget.searchTerm,
viewFilter: finampUserHelper.currentUser?.currentView?.id,
nullableViewFilters: settings.showDownloadsWithUnknownLibrary);

var items =
offlineItems.map((e) => e.baseItem).whereNotNull().toList();

items = sortItems(items, settings.tabSortBy[TabContentType.songs],
settings.tabSortOrder[TabContentType.songs]);

await _queueService.startPlayback(
items: items,
startingIndex: widget.isShownInSearch
? items.indexWhere((element) => element.id == widget.item.id)
: await widget.index,
source: QueueItemSource(
name: QueueItemSourceName(
type: QueueItemSourceNameType.preTranslated,
pretranslatedName:
AppLocalizations.of(context)!.placeholderSource),
type: QueueItemSourceType.allSongs,
id: widget.item.id,
),
);
} else {
await _audioServiceHelper.startInstantMixForItem(widget.item);
}
}
},
child: (widget.isSong || !playable)
? listTile
: Dismissible(
Expand Down
4 changes: 2 additions & 2 deletions lib/components/album_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class AlbumImage extends ConsumerWidget {
)).select((value) => (value, item?.blurHash)),
imageProviderCallback: themeCallback == null
? null
: (image) =>
FinampTheme.fromImageDeferred(image, item?.blurHash),
: (image) => themeCallback!(
FinampTheme.fromImageDeferred(image, item?.blurHash)),
placeholderBuilder: placeholderBuilder);
return disabled
? Opacity(
Expand Down
2 changes: 1 addition & 1 deletion lib/components/themed_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Future<void> showThemedBottomSheet({
WrapperBuilder? buildWrapper,
bool usePlayerTheme = false,
required FinampTheme? themeProvider,
double minDraggableHeight = 0.4,
double minDraggableHeight = 0.6,
bool showDragHandle = true,
}) async {
if (usePlayerTheme) {
Expand Down
12 changes: 8 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'dart:async';
import 'dart:io';

import 'package:audio_service/audio_service.dart';
import 'package:audio_session/audio_session.dart';
import 'package:background_downloader/background_downloader.dart';
import 'package:Finamp/color_schemes.g.dart';
import 'package:Finamp/screens/downloads_settings_screen.dart';
import 'package:Finamp/screens/interaction_settings_screen.dart';
Expand All @@ -20,6 +17,9 @@ import 'package:Finamp/services/offline_listen_helper.dart';
import 'package:Finamp/services/playback_history_service.dart';
import 'package:Finamp/services/queue_service.dart';
import 'package:Finamp/services/theme_provider.dart';
import 'package:audio_service/audio_service.dart';
import 'package:audio_session/audio_session.dart';
import 'package:background_downloader/background_downloader.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down Expand Up @@ -544,7 +544,11 @@ class _FinampState extends ConsumerState<Finamp> with WindowListener {
return;
}

//!!! destroying the window manager instance doesn't seem to work on Windows release builds, the app just freezes instead
// Destroy player on platforms using mediaKit.
if (Platform.isWindows || Platform.isLinux) {
await GetIt.instance<MusicPlayerBackgroundTask>().dispose();
windowManagerLogger.info("Player disposed.");
}
}
}

Expand Down
Loading

0 comments on commit 96c73ff

Please sign in to comment.