Skip to content

Commit

Permalink
初回起動時のデフォルトスタイルID選択のとき、「ノーマル」を最初から選ばれている状態にする (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba authored Sep 30, 2022
1 parent 8ba551d commit f5fe819
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 98 deletions.
5 changes: 0 additions & 5 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,11 +1084,6 @@ ipcMainHandle("CHANGE_PIN_WINDOW", () => {
}
});

ipcMainHandle("IS_UNSET_DEFAULT_STYLE_ID", (_, speakerUuid) => {
const defaultStyleIds = store.get("defaultStyleIds");
return !defaultStyleIds.find((style) => style.speakerUuid === speakerUuid);
});

ipcMainHandle("GET_DEFAULT_HOTKEY_SETTINGS", () => {
return defaultHotkeySettings;
});
Expand Down
76 changes: 13 additions & 63 deletions src/components/DefaultStyleSelectDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,9 @@
<q-header class="q-py-sm">
<q-toolbar>
<div class="column">
<q-toolbar-title
v-if="isFirstTime && showCharacterInfos.length > 0"
class="text-display text-h6"
>「{{ showCharacterInfos[pageIndex].metas.speakerName }}」の{{
showCharacterInfos[pageIndex].metas.styles.length > 1
? "デフォルトのスタイル(喋り方)を選んでください"
: "サンプル音声を視聴できます"
}}
</q-toolbar-title>
<q-toolbar-title v-else class="text-display"
<q-toolbar-title class="text-display"
>設定 / デフォルトスタイル・試聴</q-toolbar-title
>
<span
v-if="
isFirstTime &&
showCharacterInfos.length > 0 &&
showCharacterInfos[pageIndex].metas.styles.length > 1
"
class="text-display text-caption q-ml-sm"
>
※後からでも変更できます
</span>
</div>

<q-space />
Expand All @@ -48,11 +29,11 @@
/>

<div class="text-subtitle2 text-no-wrap text-display q-mr-md">
{{ pageIndex + 1 }} / {{ showCharacterInfos.length }}
{{ pageIndex + 1 }} / {{ multiStyleCharacterInfos.length }}
</div>

<q-btn
v-if="pageIndex + 1 < showCharacterInfos.length"
v-if="pageIndex + 1 < multiStyleCharacterInfos.length"
v-show="canNext"
unelevated
label="次へ"
Expand Down Expand Up @@ -84,18 +65,20 @@
>
<div class="character-portrait-wrapper">
<img
v-if="showCharacterInfos.length > 0"
:src="showCharacterInfos[pageIndex].portraitPath"
v-if="multiStyleCharacterInfos.length > 0"
:src="multiStyleCharacterInfos[pageIndex].portraitPath"
class="character-portrait"
/>
</div>
</q-drawer>

<q-page-container>
<q-page v-if="showCharacterInfos && selectedStyleIndexes">
<q-page v-if="multiStyleCharacterInfos && selectedStyleIndexes">
<q-tab-panels v-model="pageIndex">
<q-tab-panel
v-for="(characterInfo, characterIndex) of showCharacterInfos"
v-for="(
characterInfo, characterIndex
) of multiStyleCharacterInfos"
:key="characterIndex"
:name="characterIndex"
>
Expand Down Expand Up @@ -215,56 +198,25 @@ export default defineComponent({
);
});
// アップデートで増えたスタイルがあれば、それらに対して起動時にデフォルトスタイル選択を問うための変数
// その他の場合は、characterInfosと同じになる
// FIXME: 現状はスタイルが増えてもデフォルトスタイルを問えないので、そこを改修しなければならない
const showCharacterInfos = ref(multiStyleCharacterInfos.value);
const isFirstTime = ref(false);
const selectedStyleIndexes = ref<(number | undefined)[]>([]);
// ダイアログが開かれたときに初期値を求める
watch(
() => props.modelValue,
async (newValue, oldValue) => {
if (!oldValue && newValue) {
showCharacterInfos.value = [];
selectedStyleIndexes.value = await Promise.all(
multiStyleCharacterInfos.value.map(async (info) => {
const styles = info.metas.styles;
const isUnsetDefaultStyleId = await store.dispatch(
"IS_UNSET_DEFAULT_STYLE_ID",
{ speakerUuid: info.metas.speakerUuid }
);
if (isUnsetDefaultStyleId) {
isFirstTime.value = true;
showCharacterInfos.value.push(info);
return undefined;
}
const defaultStyleId = store.state.defaultStyleIds.find(
(x) => x.speakerUuid === info.metas.speakerUuid
)?.defaultStyleId;
const index = styles.findIndex(
const index = info.metas.styles.findIndex(
(style) => style.styleId === defaultStyleId
);
return index === -1 ? undefined : index;
})
);
if (!isFirstTime.value) {
showCharacterInfos.value = multiStyleCharacterInfos.value;
} else {
selectedStyleIndexes.value = showCharacterInfos.value.map(
(info) => {
if (info.metas.styles.length > 1) {
return undefined;
} else {
return 0;
}
}
);
}
}
}
);
Expand All @@ -273,7 +225,7 @@ export default defineComponent({
selectedStyleIndexes.value[characterIndex] = styleIndex;
// 音声を再生する。同じ話者/styleIndexだったら停止する。
const selectedCharacter = showCharacterInfos.value[characterIndex];
const selectedCharacter = multiStyleCharacterInfos.value[characterIndex];
const selectedStyleInfo = selectedCharacter.metas.styles[styleIndex];
if (
playing.value !== undefined &&
Expand Down Expand Up @@ -335,7 +287,7 @@ export default defineComponent({
const defaultStyleIds = JSON.parse(
JSON.stringify(store.state.defaultStyleIds)
) as DefaultStyleId[];
showCharacterInfos.value.forEach((info, idx) => {
multiStyleCharacterInfos.value.forEach((info, idx) => {
const defaultStyleInfo = {
speakerUuid: info.metas.speakerUuid,
defaultStyleId:
Expand All @@ -351,7 +303,6 @@ export default defineComponent({
}
});
store.dispatch("SET_DEFAULT_STYLE_IDS", defaultStyleIds);
isFirstTime.value = false;
stop();
modelValueComputed.value = false;
Expand All @@ -360,8 +311,7 @@ export default defineComponent({
return {
modelValueComputed,
showCharacterInfos,
isFirstTime,
multiStyleCharacterInfos,
selectedStyleIndexes,
selectStyleIndex,
pageIndex,
Expand Down
4 changes: 0 additions & 4 deletions src/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ const api: Sandbox = {
return ipcRenderer.invoke("HOTKEY_SETTINGS", { newData });
},

isUnsetDefaultStyleId: async (speakerUuid: string) => {
return await ipcRendererInvoke("IS_UNSET_DEFAULT_STYLE_ID", speakerUuid);
},

getDefaultHotkeySettings: async () => {
return await ipcRendererInvoke("GET_DEFAULT_HOTKEY_SETTINGS");
},
Expand Down
4 changes: 0 additions & 4 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,12 @@ export const indexStore: VoiceVoxStoreOptions<
);
return newSpeakerUuid;
},
async IS_UNSET_DEFAULT_STYLE_ID(_, { speakerUuid }) {
return await window.electron.isUnsetDefaultStyleId(speakerUuid);
},
async LOAD_DEFAULT_STYLE_IDS({ commit, state }) {
let defaultStyleIds = await window.electron.getSetting("defaultStyleIds");

if (!state.characterInfos) throw new Error("characterInfos is undefined");

// デフォルトスタイルが設定されていない場合は0をセットする
// FIXME: 保存しているものとstateのものが異なってしまうので良くない。デフォルトスタイルが未設定の場合はAudioCellsを表示しないようにすべき
const unsetCharacterInfos = state.characterInfos.filter(
(characterInfo) =>
!defaultStyleIds.some(
Expand Down
4 changes: 0 additions & 4 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,6 @@ type IndexStoreTypes = {
action(): Promise<string>;
};

IS_UNSET_DEFAULT_STYLE_ID: {
action(payload: { speakerUuid: string }): Promise<boolean>;
};

LOAD_DEFAULT_STYLE_IDS: {
action(): Promise<void>;
};
Expand Down
5 changes: 0 additions & 5 deletions src/type/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,6 @@ export type IpcIHData = {
return: HotkeySetting[];
};

IS_UNSET_DEFAULT_STYLE_ID: {
args: [speakerUuid: string];
return: boolean;
};

GET_DEFAULT_HOTKEY_SETTINGS: {
args: [];
return: HotkeySetting[];
Expand Down
1 change: 0 additions & 1 deletion src/type/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export interface Sandbox {
hotkeySettings(newData?: HotkeySetting): Promise<HotkeySetting[]>;
checkFileExists(file: string): Promise<boolean>;
changePinWindow(): void;
isUnsetDefaultStyleId(speakerUuid: string): Promise<boolean>;
getDefaultHotkeySettings(): Promise<HotkeySetting[]>;
getDefaultToolbarSetting(): Promise<ToolbarSetting>;
theme(newData?: string): Promise<ThemeSetting | void>;
Expand Down
12 changes: 0 additions & 12 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -476,18 +476,6 @@ export default defineComponent({
const newCharacters = await store.dispatch("GET_NEW_CHARACTERS");
isCharacterOrderDialogOpenComputed.value = newCharacters.length > 0;
// スタイルが複数あって未選択なキャラがいる場合はデフォルトスタイル選択ダイアログを表示
let isUnsetDefaultStyleIds = false;
if (characterInfos.value == undefined) throw new Error();
for (const info of characterInfos.value) {
isUnsetDefaultStyleIds ||=
info.metas.styles.length > 1 &&
(await store.dispatch("IS_UNSET_DEFAULT_STYLE_ID", {
speakerUuid: info.metas.speakerUuid,
}));
}
isDefaultStyleSelectDialogOpenComputed.value = isUnsetDefaultStyleIds;
// 最初のAudioCellを作成
const audioItem: AudioItem = await store.dispatch(
"GENERATE_AUDIO_ITEM",
Expand Down

0 comments on commit f5fe819

Please sign in to comment.