Skip to content

Commit

Permalink
stop playback resets the length and returns correct status, resetting…
Browse files Browse the repository at this point in the history
… Nuclear stops playback
  • Loading branch information
sicin committed Sep 22, 2024
1 parent 280327b commit 3da7774
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 27 deletions.
1 change: 1 addition & 0 deletions packages/app/app/actions/actionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export enum Toast {
export enum Player {
START_PLAYBACK = 'START_PLAYBACK',
PAUSE_PLAYBACK = 'PAUSE_PLAYBACK',
STOP_PLAYBACK = 'STOP_PLAYBACK',
UPDATE_PLAYBACK_PROGRESS = 'UPDATE_PLAYBACK_PROGRESS',
UPDATE_SEEK = 'UPDATE_SEEK',
UPDATE_VOLUME = 'UPDATE_VOLUME',
Expand Down
12 changes: 9 additions & 3 deletions packages/app/app/actions/player.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Sound from 'react-hifi';
import { setOption } from '@nuclear/core';
import Sound from 'react-hifi';
import { createStandardAction } from 'typesafe-actions';
import { Player } from './actionTypes';
import { PlaybackStatus } from '../reducers/player';
import { Player } from './actionTypes';

export const startPlayback = createStandardAction(Player.START_PLAYBACK).map((fromMain: boolean) => {
return {
Expand All @@ -16,6 +16,12 @@ export const pausePlayback = createStandardAction(Player.PAUSE_PLAYBACK).map((fr
};
});

export const stopPlayback = createStandardAction(Player.STOP_PLAYBACK).map((fromMain: boolean) => {
return {
meta: { fromMain }
};
});

export function togglePlayback(currentState: PlaybackStatus, fromMain: boolean) {
return dispatch => {
if (currentState === Sound.status.PLAYING) {
Expand All @@ -29,7 +35,7 @@ export function togglePlayback(currentState: PlaybackStatus, fromMain: boolean)
export function resetPlayer() {
return dispatch => {
dispatch(updatePlaybackProgress(0, 0));
dispatch(pausePlayback(false));
dispatch(stopPlayback(false));
dispatch(updateStreamLoading(false));
};
}
Expand Down
20 changes: 10 additions & 10 deletions packages/app/app/containers/IpcContainer/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { IpcEvents } from '@nuclear/core';
import { ipcRenderer } from 'electron';
import logger from 'electron-timber';
import { head } from 'lodash';
import React from 'react';
import { withRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { bindActionCreators } from 'redux';
import { head } from 'lodash';
import logger from 'electron-timber';
import { ipcRenderer } from 'electron';
import { getType } from 'typesafe-actions';
import { IpcEvents } from '@nuclear/core';

import * as DownloadsActions from '../../actions/downloads';
import * as EqualizerActions from '../../actions/equalizer';
import { localLibraryActions } from '../../actions/local';
import * as PlayerActions from '../../actions/player';
import * as PlaylistActions from '../../actions/playlists';
import * as QueueActions from '../../actions/queue';
import * as SettingsActions from '../../actions/settings';
import * as PlaylistActions from '../../actions/playlists';
import * as EqualizerActions from '../../actions/equalizer';
import * as DownloadsActions from '../../actions/downloads';
import { localLibraryActions } from '../../actions/local';

class IpcContainer extends React.Component {
componentDidMount() {
Expand All @@ -26,7 +26,7 @@ class IpcContainer extends React.Component {
ipcRenderer.on(IpcEvents.PREVIOUS, () => actions.previousSong());
ipcRenderer.on(IpcEvents.PAUSE, () => actions.pausePlayback(true));
ipcRenderer.on(IpcEvents.PLAYPAUSE, () => actions.togglePlayback(this.props.player.playbackStatus, true));
ipcRenderer.on(IpcEvents.STOP, () => actions.pausePlayback(true));
ipcRenderer.on(IpcEvents.STOP, () => actions.stopPlayback(true));
ipcRenderer.on(IpcEvents.PLAY, () => actions.startPlayback(true));
ipcRenderer.on(IpcEvents.MUTE, () => {
if (this.props.player.muted) {
Expand Down
8 changes: 6 additions & 2 deletions packages/app/app/reducers/player.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Sound from 'react-hifi';
import { getOption } from '@nuclear/core';
import Sound from 'react-hifi';
import { ActionType, getType } from 'typesafe-actions';
import * as PlayerActions from '../actions/player';
import {
nextSongAction,
previousSongAction,
selectSong
} from '../actions/queue';
import { ActionType, getType } from 'typesafe-actions';

export type PlaybackStatus = 'PAUSED' | 'PLAYING' | 'STOPPED'

Expand Down Expand Up @@ -46,6 +46,10 @@ export default function PlayerReducer(state=initialState(), action: PlayerReduce
return Object.assign({}, state, {
playbackStatus: Sound.status.PAUSED
});
case getType(PlayerActions.stopPlayback):
return Object.assign({}, state, {
playbackStatus: Sound.status.STOPPED
});
case getType(PlayerActions.updatePlaybackProgress):
return Object.assign({}, state, {
playbackProgress: action.payload.progress,
Expand Down
12 changes: 7 additions & 5 deletions packages/app/app/store/middlewares/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { getOption, IpcEvents, isValidPort } from '@nuclear/core';
import { ipcRenderer } from 'electron';
import _ from 'lodash';
import { LocalLibrary } from '../../actions/actionTypes';
import { Queue, Settings } from '../../actions/actionTypes';
import { Middleware } from 'redux';
import { getType } from 'typesafe-actions';
import { LocalLibrary, Queue, Settings } from '../../actions/actionTypes';
import { changeConnectivity } from '../../actions/connectivity';
import * as DownloadActions from '../../actions/downloads';
import * as PlayerActions from '../../actions/player';
import { CLOSE_WINDOW, MINIMIZE_WINDOW, MAXIMIZE_WINDOW, OPEN_DEVTOOLS } from '../../actions/window';
import { getType } from 'typesafe-actions';
import { Middleware } from 'redux';
import { CLOSE_WINDOW, MAXIMIZE_WINDOW, MINIMIZE_WINDOW, OPEN_DEVTOOLS } from '../../actions/window';

type IpcActionType = {
type: string;
Expand Down Expand Up @@ -45,6 +44,9 @@ const ipcConnect: Middleware = () => next => {
case getType(PlayerActions.pausePlayback):
ipcRenderer.send(IpcEvents.PAUSE);
break;
case getType(PlayerActions.stopPlayback):
ipcRenderer.send(IpcEvents.STOP);
break;

case LocalLibrary.SCAN_LOCAL_FOLDERS:
ipcRenderer.send(IpcEvents.LOCALFOLDERS_REFRESH);
Expand Down
18 changes: 13 additions & 5 deletions packages/main/src/services/@linux/system-api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { NuclearStatus, NuclearMeta, NuclearPlaylist, PlaybackStatus, IpcEvents } from '@nuclear/core';
import { IpcEvents, NuclearMeta, NuclearPlaylist, NuclearStatus, PlaybackStatus } from '@nuclear/core';
import autobind from 'autobind-decorator';
import { app, IpcMain, Event } from 'electron';
import { app, Event, IpcMain } from 'electron';
import { inject } from 'inversify';
import MprisService, { MprisPlaylist, MprisMeta, PlaybackStatus as MprisStatus, LoopStatus } from 'mpris-service';
import MprisService, { LoopStatus, MprisMeta, MprisPlaylist, PlaybackStatus as MprisStatus } from 'mpris-service';

import NuclearApi from '../../interfaces/nuclear-api';
import { systemMediaController, systemMediaEvent, SYSTEM_MEDIA_EVENT_KEY } from '../../utils/decorators';
import { SYSTEM_MEDIA_EVENT_KEY, systemMediaController, systemMediaEvent } from '../../utils/decorators';
import { ControllerMeta } from '../../utils/types';
import Config from '../config';
import Discord from '../discord';
Expand Down Expand Up @@ -138,9 +138,17 @@ class LinuxMediaService extends MprisService implements NuclearApi {

@systemMediaEvent('stop')
onStop() {
this.playbackStatus = MprisService.PLAYBACK_STATUS_STOPED;
this.playbackStatus = MprisService.PLAYBACK_STATUS_STOPPED;
this.discord.clear();
this.metadata['mpris:length'] = 0;
this.window.send(IpcEvents.STOP);
this.sendMetadata({
artist: 'Nuclear',
name: '',
uuid: '0',
thumbnail: '',
streams: []
});
}

@systemMediaEvent('playpause')
Expand Down
4 changes: 2 additions & 2 deletions packages/main/typings/mpris-service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ declare module 'mpris-service' {
enum playbackStatus {
PLAYING = 'playing',
PAUSED = 'paused',
STOPED = 'stoped',
STOPPED = 'stopped',
}

export type LoopStatus = loopStatus;
Expand All @@ -49,7 +49,7 @@ declare module 'mpris-service' {

static PLAYBACK_STATUS_PLAYING: playbackStatus.PLAYING;
static PLAYBACK_STATUS_PAUSED: playbackStatus.PAUSED;
static PLAYBACK_STATUS_STOPED: playbackStatus.STOPED;
static PLAYBACK_STATUS_STOPPED: playbackStatus.STOPPED;

playlists: MprisPlaylist[];
shuffle: boolean;
Expand Down

0 comments on commit 3da7774

Please sign in to comment.