From 860292bf57267dbbbc57b29f932403496696fc52 Mon Sep 17 00:00:00 2001 From: ci7lus <7887955+ci7lus@users.noreply.github.com> Date: Sat, 20 Nov 2021 16:17:52 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20SelectedService=E3=82=92globalFa?= =?UTF-8?q?mily=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 番組表でサービス切り替えができるように --- src/atoms/contentPlayer.ts | 6 ------ src/atoms/contentPlayerResolvedFamilies.ts | 8 +++++++- src/atoms/globalFamilies.ts | 14 +++++++++++++- src/atoms/globalFamilyKeys.ts | 2 ++ src/components/contentPlayer/Controller.tsx | 2 +- src/components/contentPlayer/MirakurunManager.tsx | 6 ++++-- src/constants/recoil.ts | 6 +++++- src/utils/contextmenu.ts | 2 +- src/windows/ProgramTable.tsx | 8 ++++++-- 9 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/atoms/contentPlayer.ts b/src/atoms/contentPlayer.ts index 54d462a..62a70ef 100644 --- a/src/atoms/contentPlayer.ts +++ b/src/atoms/contentPlayer.ts @@ -1,6 +1,5 @@ import { atom } from "recoil" import pkg from "../../package.json" -import { Service } from "../infra/mirakurun/api" import type { AribSubtitleData, ContentPlayerKeyForRestoration, @@ -9,11 +8,6 @@ import { VLCAudioChannel } from "../utils/vlc" const prefix = `${pkg.name}.contentPlayer` -export const contentPlayerSelectedServiceAtom = atom({ - key: `${prefix}.selectedService`, - default: null, -}) - export const contentPlayerTitleAtom = atom({ key: `${prefix}.title`, default: null, diff --git a/src/atoms/contentPlayerResolvedFamilies.ts b/src/atoms/contentPlayerResolvedFamilies.ts index 1384807..908bcf6 100644 --- a/src/atoms/contentPlayerResolvedFamilies.ts +++ b/src/atoms/contentPlayerResolvedFamilies.ts @@ -1,5 +1,11 @@ import { remoteWindow } from "../utils/remote" -import { globalContentPlayerPlayingContentFamily } from "./globalFamilies" +import { + globalContentPlayerPlayingContentFamily, + globalContentPlayerSelectedServiceFamily, +} from "./globalFamilies" export const contentPlayerPlayingContentAtom = globalContentPlayerPlayingContentFamily(remoteWindow.id) + +export const contentPlayerSelectedServiceAtom = + globalContentPlayerSelectedServiceFamily(remoteWindow.id) diff --git a/src/atoms/globalFamilies.ts b/src/atoms/globalFamilies.ts index 165a772..123a446 100644 --- a/src/atoms/globalFamilies.ts +++ b/src/atoms/globalFamilies.ts @@ -1,7 +1,11 @@ import { atomFamily } from "recoil" +import { Service } from "../infra/mirakurun/api" import { ContentPlayerPlayingContent } from "../types/contentPlayer" -import { globalContentPlayerPlayingContentFamilyKey } from "./globalFamilyKeys" +import { + globalContentPlayerPlayingContentFamilyKey, + globalContentPlayerSelectedServiceFamilyKey, +} from "./globalFamilyKeys" export const globalContentPlayerPlayingContentFamily = atomFamily< ContentPlayerPlayingContent | null, @@ -10,3 +14,11 @@ export const globalContentPlayerPlayingContentFamily = atomFamily< key: globalContentPlayerPlayingContentFamilyKey, default: null, }) + +export const globalContentPlayerSelectedServiceFamily = atomFamily< + Service | null, + number +>({ + key: globalContentPlayerSelectedServiceFamilyKey, + default: null, +}) diff --git a/src/atoms/globalFamilyKeys.ts b/src/atoms/globalFamilyKeys.ts index b436d40..11156b1 100644 --- a/src/atoms/globalFamilyKeys.ts +++ b/src/atoms/globalFamilyKeys.ts @@ -3,3 +3,5 @@ import pkg from "../../package.json" const prefix = `${pkg.name}.global` export const globalContentPlayerPlayingContentFamilyKey = `${prefix}.playingContent` + +export const globalContentPlayerSelectedServiceFamilyKey = `${prefix}.selectedService` diff --git a/src/components/contentPlayer/Controller.tsx b/src/components/contentPlayer/Controller.tsx index 33a9bb5..b85fda5 100644 --- a/src/components/contentPlayer/Controller.tsx +++ b/src/components/contentPlayer/Controller.tsx @@ -15,11 +15,11 @@ import { contentPlayerPlayingTimeAtom, contentPlayerPositionUpdateTriggerAtom, contentPlayerScreenshotTriggerAtom, - contentPlayerSelectedServiceAtom, contentPlayerServiceLogoUrlAtom, contentPlayerSubtitleEnabledAtom, contentPlayerVolumeAtom, } from "../../atoms/contentPlayer" +import { contentPlayerSelectedServiceAtom } from "../../atoms/contentPlayerResolvedFamilies" import { contentPlayerProgramSelector, contentPlayerServiceSelector, diff --git a/src/components/contentPlayer/MirakurunManager.tsx b/src/components/contentPlayer/MirakurunManager.tsx index 09fcbe2..5e8e553 100644 --- a/src/components/contentPlayer/MirakurunManager.tsx +++ b/src/components/contentPlayer/MirakurunManager.tsx @@ -5,10 +5,12 @@ import { useRecoilState, useRecoilValue, useSetRecoilState } from "recoil" import { contentPlayerIsPlayingAtom, contentPlayerKeyForRestorationAtom, - contentPlayerSelectedServiceAtom, contentPlayerServiceLogoUrlAtom, } from "../../atoms/contentPlayer" -import { contentPlayerPlayingContentAtom } from "../../atoms/contentPlayerResolvedFamilies" +import { + contentPlayerPlayingContentAtom, + contentPlayerSelectedServiceAtom, +} from "../../atoms/contentPlayerResolvedFamilies" import { contentPlayerServiceSelector, contentPlayerUrlSelector, diff --git a/src/constants/recoil.ts b/src/constants/recoil.ts index 5690ef2..c908096 100644 --- a/src/constants/recoil.ts +++ b/src/constants/recoil.ts @@ -3,7 +3,10 @@ import { contentPlayerKeyForRestorationAtom, contentPlayerVolumeAtom, } from "../atoms/contentPlayer" -import { globalContentPlayerPlayingContentFamilyKey } from "../atoms/globalFamilyKeys" +import { + globalContentPlayerPlayingContentFamilyKey, + globalContentPlayerSelectedServiceFamilyKey, +} from "../atoms/globalFamilyKeys" import { globalActiveContentPlayerIdAtomKey } from "../atoms/globalKeys" import { mirakurunServicesAtom } from "../atoms/mirakurun" import { @@ -24,6 +27,7 @@ export const RECOIL_SHARED_ATOM_KEYS = [ mirakurunServicesAtom.key, globalActiveContentPlayerIdAtomKey, globalContentPlayerPlayingContentFamilyKey, + globalContentPlayerSelectedServiceFamilyKey, ] export const RECOIL_STORED_ATOM_KEYS = [ diff --git a/src/utils/contextmenu.ts b/src/utils/contextmenu.ts index 811909c..ef8d332 100644 --- a/src/utils/contextmenu.ts +++ b/src/utils/contextmenu.ts @@ -3,8 +3,8 @@ import { useRecoilState, useRecoilValue } from "recoil" import { contentPlayerIsPlayingAtom, contentPlayerKeyForRestorationAtom, - contentPlayerSelectedServiceAtom, } from "../atoms/contentPlayer" +import { contentPlayerSelectedServiceAtom } from "../atoms/contentPlayerResolvedFamilies" import { mirakurunServicesAtom } from "../atoms/mirakurun" import { REUQEST_OPEN_WINDOW } from "../constants/ipc" import { ROUTES } from "../constants/routes" diff --git a/src/windows/ProgramTable.tsx b/src/windows/ProgramTable.tsx index 5396d6c..0e1eb4b 100644 --- a/src/windows/ProgramTable.tsx +++ b/src/windows/ProgramTable.tsx @@ -2,7 +2,8 @@ import clsx from "clsx" import React, { useEffect, useState } from "react" import { useSetRecoilState, useRecoilValue } from "recoil" import pkg from "../../package.json" -import { contentPlayerSelectedServiceAtom } from "../atoms/contentPlayer" +import { globalContentPlayerSelectedServiceFamily } from "../atoms/globalFamilies" +import { globalActiveContentPlayerIdSelector } from "../atoms/globalSelectors" import { mirakurunServicesAtom } from "../atoms/mirakurun" import { mirakurunSetting } from "../atoms/settings" import { ScrollArea } from "../components/programTable/ScrollArea" @@ -13,7 +14,10 @@ import { remoteWindow } from "../utils/remote" export const CoiledProgramTable: React.VFC<{}> = () => { const now = useNow() const [add, setAdd] = useState(0) - const setSelectedService = useSetRecoilState(contentPlayerSelectedServiceAtom) + const activePlayerId = useRecoilValue(globalActiveContentPlayerIdSelector) + const setSelectedService = useSetRecoilState( + globalContentPlayerSelectedServiceFamily(activePlayerId ?? 0) + ) const services = useRecoilValue(mirakurunServicesAtom) const mirakurunSettingValue = useRecoilValue(mirakurunSetting)