Skip to content

Commit

Permalink
feat: persist currently playing episode
Browse files Browse the repository at this point in the history
  • Loading branch information
chhoumann committed Jul 28, 2022
1 parent e6d32a7 commit b31b094
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main.ts
Expand Up @@ -19,6 +19,8 @@ import { Playlist } from './types/Playlist';
import { PlaylistController } from './store_controllers/PlaylistController';
import { QueueController } from './store_controllers/QueueController';
import { FavoritesController } from './store_controllers/FavoritesController';
import { Episode } from './types/Episode';
import CurrentEpisodeController from './store_controllers/CurrentEpisodeController';

export default class PodNotes extends Plugin implements IPodNotes {
public api: IAPI;
Expand All @@ -31,6 +33,7 @@ export default class PodNotes extends Plugin implements IPodNotes {
private playlistController: StoreController<{ [playlistName: string]: Playlist }>;
private queueController: StoreController<Playlist>;
private favoritesController: StoreController<Playlist>;
private currentEpisodeController: StoreController<Episode>;

async onload() {
plugin.set(this);
Expand All @@ -42,12 +45,14 @@ export default class PodNotes extends Plugin implements IPodNotes {
playlists.set(this.settings.playlists);
queue.set(this.settings.queue);
favorites.set(this.settings.favorites);
currentEpisode.set(this.settings.currentEpisode);

this.playedEpisodeController = new EpisodeStatusController(playedEpisodes, this).on();
this.savedFeedsController = new SavedFeedsController(savedFeeds, this).on();
this.playlistController = new PlaylistController(playlists, this).on();
this.queueController = new QueueController(queue, this).on();
this.favoritesController = new FavoritesController(favorites, this).on();
this.currentEpisodeController = new CurrentEpisodeController(currentEpisode, this).on();

this.addCommand({
id: 'start-playing',
Expand Down Expand Up @@ -157,6 +162,7 @@ export default class PodNotes extends Plugin implements IPodNotes {
this?.playlistController.off();
this?.queueController.off();
this?.favoritesController.off();
this?.currentEpisodeController.off();
}

async loadSettings() {
Expand Down
2 changes: 1 addition & 1 deletion src/store/index.ts
Expand Up @@ -16,6 +16,7 @@ export const currentEpisode = function () {

return {
subscribe,
update,
set: (newEpisode: Episode) => {
update(previousEpisode => {
if (previousEpisode) {
Expand All @@ -28,7 +29,6 @@ export const currentEpisode = function () {
}
}();


export const isPaused = writable<boolean>(true);
export const playedEpisodes = function () {
const store = writable<{ [key: string]: PlayedEpisode }>({});
Expand Down
19 changes: 19 additions & 0 deletions src/store_controllers/CurrentEpisodeController.ts
@@ -0,0 +1,19 @@
import { Episode } from "src/types/Episode";
import { IPodNotes } from "src/types/IPodNotes";
import { StoreController } from "src/types/StoreController";
import { Writable } from "svelte/store";

export default class CurrentEpisodeController extends StoreController<Episode> {
private plugin: IPodNotes;

constructor(store: Writable<Episode>, plugin: IPodNotes) {
super(store);
this.plugin = plugin;
}

protected onChange(value: Episode) {
this.plugin.settings.currentEpisode = value;

this.plugin.saveSettings();
}
}
2 changes: 2 additions & 0 deletions src/types/IPodNotesSettings.ts
Expand Up @@ -2,6 +2,7 @@ import { PodNote } from './PodNotes';
import { PodcastFeed } from "./PodcastFeed";
import { PlayedEpisode } from './PlayedEpisode';
import { Playlist } from './Playlist';
import { Episode } from './Episode';

export interface IPodNotesSettings {
savedFeeds: { [podcastName: string]: PodcastFeed };
Expand All @@ -13,4 +14,5 @@ export interface IPodNotesSettings {
playlists: { [playlistName: string]: Playlist }
queue: Playlist,
favorites: Playlist,
currentEpisode: Episode,
}

0 comments on commit b31b094

Please sign in to comment.