Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit dbb3fe6

Browse files
committed
Stop rodio player on reload and app close
1 parent 332a7f5 commit dbb3fe6

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/utils/main/ipc/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { ipcMain } from 'electron'
2626
let scannerChannel: ScannerChannel | undefined = undefined
2727
let updateChannel: UpdateChannel | undefined = undefined
2828
let extensionChannel: ExtensionHostChannel | undefined = undefined
29+
let rodioChannel: RodioChannel | undefined = undefined
2930
let preferenceChannel: PreferenceChannel | undefined = undefined
3031
let storeChannel: StoreChannel | undefined = undefined
3132
let mprisChannel: MprisChannel | undefined = undefined
@@ -46,11 +47,18 @@ export function registerIpcChannels() {
4647
new NotifierChannel(),
4748
getMprisChannel(),
4849
getSpotifyPlayerChannel(),
49-
new RodioChannel(),
50+
getRodioChannel(),
5051
]
5152
ipcChannels.forEach((channel) => ipcMain.on(channel.name, (event, request) => channel.handle(event, request)))
5253
}
5354

55+
export function getRodioChannel() {
56+
if (!rodioChannel) {
57+
rodioChannel = new RodioChannel()
58+
}
59+
return rodioChannel
60+
}
61+
5462
export function getExtensionHostChannel() {
5563
if (!extensionChannel) {
5664
extensionChannel = new ExtensionHostChannel()

src/utils/main/ipc/rodio.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ export class RodioChannel implements IpcChannelInterface {
8282
event.reply(request.responseChannel)
8383
}
8484

85-
private async stop(event: Electron.IpcMainEvent, request: IpcRequest) {
85+
public async stop(event?: Electron.IpcMainEvent, request?: IpcRequest) {
8686
try {
8787
await this.rodioInstance?.stop()
8888
} catch (e) {
8989
this.emitError(e)
9090
}
91-
event.reply(request.responseChannel)
91+
event?.reply(request?.responseChannel ?? '')
9292
}
9393

9494
private async setVolume(event: Electron.IpcMainEvent, request: IpcRequest<RodioRequests.Volume>) {

src/utils/main/windowManager.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
import { ButtonEnum, PlayerButtons } from 'media-controller'
2525
import { SongEvents, WindowEvents } from './ipc/constants'
2626
import { access, readFile } from 'fs/promises'
27-
import { getMprisChannel, getSpotifyPlayerChannel } from './ipc/index'
27+
import { getMprisChannel, getRodioChannel, getSpotifyPlayerChannel } from './ipc/index'
2828
import { getWindowSize, loadPreferences, setWindowSize } from './db/preferences'
2929

3030
import { $t } from './i18nLoader'
@@ -314,6 +314,7 @@ export class WindowHandler {
314314
}
315315

316316
public async stopAll() {
317+
getRodioChannel().stop()
317318
getSpotifyPlayerChannel().closePlayer()
318319
// Stop extension Host
319320
await getExtensionHostChannel().closeExtensionHost()
@@ -352,10 +353,6 @@ export class WindowHandler {
352353
}
353354
}
354355
})
355-
// window.webContents.on('', (event, url) {
356-
// event.preventDefault()
357-
// open(url)
358-
// })
359356

360357
window.webContents.on(
361358
'did-frame-navigate',

src/utils/ui/mixins/KeyHandlerMixin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export default class KeyHandlerMixin extends mixins(PlayerControls) {
8585
break
8686
case HotkeyEvents.RELOAD_PAGE:
8787
window.SpotifyPlayer.close()
88+
.then(() => window.RodioUtils.stop())
8889
.then(() => window.WindowUtils.handleReload())
8990
.then(() => location.reload())
9091
break

0 commit comments

Comments
 (0)