Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

音声書き出し時に進捗がわかるような表示を実装 #1038

Merged
merged 17 commits into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/components/Dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export async function generateAndSaveOneAudioWithDialog({
filePath?: string;
encoding?: EncodingType;
}): Promise<void> {
await dispatch("START_INDETERMINATE_PROGRESS");
const result: SaveResultObject = await dispatch("GENERATE_AND_SAVE_AUDIO", {
audioKey,
filePath,
encoding,
});
}).finally(() => dispatch("RESET_PROGRESS"));
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved

if (result.result === "SUCCESS" || result.result === "CANCELED") return;
let msg = "";
switch (result.result) {
Expand Down Expand Up @@ -65,13 +67,17 @@ export async function generateAndSaveAllAudioWithDialog({
dirPath?: string;
encoding?: EncodingType;
}): Promise<void> {
await dispatch("START_AUDIO_ITEMS_PROGRESS");
const result = await dispatch("GENERATE_AND_SAVE_ALL_AUDIO", {
dirPath,
encoding,
});
callback: () => dispatch("INCREMENT_PROGRESS"),
}).finally(() => dispatch("RESET_PROGRESS"));
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved

const successArray: Array<string | undefined> = [];
const writeErrorArray: Array<WriteErrorTypeForSaveAllResultDialog> = [];
const engineErrorArray: Array<string | undefined> = [];

if (result) {
for (const item of result) {
let msg = "";
Expand Down Expand Up @@ -121,10 +127,12 @@ export async function generateAndConnectAndSaveAudioWithDialog({
filePath?: string;
encoding?: EncodingType;
}): Promise<void> {
await dispatch("START_AUDIO_ITEMS_PROGRESS");
const result = await dispatch("GENERATE_AND_CONNECT_AND_SAVE_AUDIO", {
filePath,
encoding,
});
callback: () => dispatch("INCREMENT_PROGRESS"),
}).finally(() => dispatch("RESET_PROGRESS"));

if (
result === undefined ||
Expand Down
108 changes: 108 additions & 0 deletions src/components/ProgressDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<template>
<div v-if="isShowProgress" class="progress">
<div v-if="isDeterminate">
<q-circular-progress
show-value
:value="progress"
:min="0"
:max="1"
rounded
font-size="12px"
color="primary"
size="xl"
:thickness="0.3"
>
{{ formattedProgress }}%
</q-circular-progress>
<div class="q-mt-md">生成中です...</div>
</div>
<div v-if="!isDeterminate">
<q-circular-progress
indeterminate
color="primary"
rounded
:thickness="0.3"
size="xl"
/>
<div class="q-mt-md">生成中です...</div>
</div>
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
</div>
</template>

<script lang="ts">
import { useStore } from "@/store";
import { computed, defineComponent, onUnmounted, ref, watch } from "vue";

export default defineComponent({
name: "ProgressDialog",

setup() {
const store = useStore();

const progress = computed(() => store.getters.PROGRESS);
const isShowProgress = ref<boolean>(false);
const isDeterminate = ref<boolean>(false);

let timeoutId: ReturnType<typeof setTimeout>;

const deferredProgressStart = () => {
// 3秒待ってから表示する
timeoutId = setTimeout(() => {
isShowProgress.value = true;
}, 3000);
};

watch(progress, (newValue, oldValue) => {
if (newValue === -1) {
// → 非表示
clearTimeout(timeoutId);
isShowProgress.value = false;
} else if (oldValue === -1 && newValue <= 1) {
// 非表示 → 処理中
deferredProgressStart();
isDeterminate.value = false;
} else if (oldValue !== -1 && 0 < newValue) {
// 処理中 → 処理中(0%より大きな値)
// 0 < value <= 1の間のみ進捗を%で表示する
isDeterminate.value = true;
}
});

onUnmounted(() => clearTimeout(timeoutId));

const formattedProgress = computed(() =>
(store.getters.PROGRESS * 100).toFixed()
);

return {
isShowProgress,
isDeterminate,
progress,
formattedProgress,
};
},
});
</script>

<style lang="scss" scoped>
@use '@/styles/colors' as colors;

.progress {
background-color: rgba(colors.$display-rgb, 0.15);
position: absolute;
inset: 0;
z-index: 10;
display: flex;
text-align: center;
align-items: center;
justify-content: center;

> div {
color: colors.$display;
background: colors.$surface;
width: 200px;
border-radius: 6px;
padding: 14px 48px;
}
}
</style>
21 changes: 18 additions & 3 deletions src/store/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,11 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
action: createUILockAction(
async (
{ state, dispatch },
{ dirPath, encoding }: { dirPath?: string; encoding?: EncodingType }
{
dirPath,
encoding,
callback,
}: { dirPath?: string; encoding?: EncodingType; callback?: () => void }
) => {
if (state.savingSetting.fixedExportEnabled) {
dirPath = state.savingSetting.fixedExportDir;
Expand All @@ -1249,6 +1253,9 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
audioKey,
filePath: path.join(_dirPath, name),
encoding,
}).then((value) => {
callback?.();
return value;
});
});
return Promise.all(promises);
Expand All @@ -1261,7 +1268,11 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
action: createUILockAction(
async (
{ state, dispatch },
{ filePath, encoding }: { filePath?: string; encoding?: EncodingType }
{
filePath,
encoding,
callback,
}: { filePath?: string; encoding?: EncodingType; callback?: () => void }
): Promise<SaveResultObject> => {
const defaultFileName = buildProjectFileName(state, "wav");

Expand Down Expand Up @@ -1317,6 +1328,7 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
let blob = await dispatch("GET_AUDIO_CACHE", { audioKey });
if (!blob) {
blob = await dispatch("GENERATE_AUDIO", { audioKey });
callback?.();
}
if (blob === null) {
return { result: "ENGINE_ERROR", path: filePath };
Expand Down Expand Up @@ -1517,11 +1529,14 @@ export const audioStore = createPartialStore<AudioStoreTypes>({
// 音声用意
let blob = await dispatch("GET_AUDIO_CACHE", { audioKey });
if (!blob) {
dispatch("START_INDETERMINATE_PROGRESS");
commit("SET_AUDIO_NOW_GENERATING", {
audioKey,
nowGenerating: true,
});
blob = await dispatch("GENERATE_AUDIO", { audioKey });
blob = await dispatch("GENERATE_AUDIO", { audioKey }).finally(() =>
dispatch("RESET_PROGRESS")
);
commit("SET_AUDIO_NOW_GENERATING", {
audioKey,
nowGenerating: false,
Expand Down
33 changes: 33 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,15 @@ export type AudioStoreTypes = {
action(payload: {
dirPath?: string;
encoding?: EncodingType;
callback?: () => void;
}): SaveResultObject[] | undefined;
};

GENERATE_AND_CONNECT_AND_SAVE_AUDIO: {
action(payload: {
filePath?: string;
encoding?: EncodingType;
callback?: () => void;
}): SaveResultObject | undefined;
};

Expand Down Expand Up @@ -979,6 +981,8 @@ export type UiStoreState = {
isMaximized: boolean;
isPinned: boolean;
isFullscreen: boolean;
progress: number;
progressCount: number;
};

export type UiStoreTypes = {
Expand All @@ -990,6 +994,10 @@ export type UiStoreTypes = {
getter: boolean;
};

PROGRESS: {
getter: number;
};

ASYNC_UI_LOCK: {
action(payload: { callback: () => Promise<void> }): void;
};
Expand Down Expand Up @@ -1109,6 +1117,31 @@ export type UiStoreTypes = {
RESTART_APP: {
action(obj: { isSafeMode?: boolean }): void;
};

START_PROGRESS: {
action(payload: { count: number }): void;
};

START_AUDIO_ITEMS_PROGRESS: {
action(): void;
};

START_INDETERMINATE_PROGRESS: {
action(): void;
};

INCREMENT_PROGRESS: {
action(): void;
};

SET_PROGRESS: {
mutation: { progress: number; count?: number };
action(payload: { progress: number; count?: number }): void;
};

RESET_PROGRESS: {
action(): void;
};
};

/*
Expand Down
51 changes: 51 additions & 0 deletions src/store/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export const uiStoreState: UiStoreState = {
isMaximized: false,
isPinned: false,
isFullscreen: false,
progress: -1,
progressCount: 0,
};

export const uiStore = createPartialStore<UiStoreTypes>({
Expand All @@ -59,6 +61,12 @@ export const uiStore = createPartialStore<UiStoreTypes>({
},
},

PROGRESS: {
getter(state) {
return state.progress;
},
},

ASYNC_UI_LOCK: {
action: createUILockAction(
async (_, { callback }: { callback: () => Promise<void> }) => {
Expand Down Expand Up @@ -322,4 +330,47 @@ export const uiStore = createPartialStore<UiStoreTypes>({
window.electron.restartApp({ isSafeMode: !!isSafeMode });
},
},

START_PROGRESS: {
action({ dispatch }, { count }) {
dispatch("SET_PROGRESS", { progress: 0, count });
},
},

START_AUDIO_ITEMS_PROGRESS: {
action({ dispatch, state }) {
dispatch("START_PROGRESS", { count: state.audioKeys.length });
},
},

INCREMENT_PROGRESS: {
action({ dispatch, state }) {
const step = 1.0 / state.progressCount;
dispatch("SET_PROGRESS", { progress: state.progress + step });
},
},

START_INDETERMINATE_PROGRESS: {
action({ dispatch }) {
dispatch("SET_PROGRESS", { progress: 0 });
},
},

SET_PROGRESS: {
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
mutation(state, { progress, count }) {
state.progress = progress;
if (count != null) {
state.progressCount = count;
}
},
action({ commit }, { progress, count }) {
commit("SET_PROGRESS", { progress, count });
},
},

RESET_PROGRESS: {
action({ dispatch }) {
dispatch("SET_PROGRESS", { progress: -1 });
},
},
});
4 changes: 4 additions & 0 deletions src/views/EditorHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<q-page-container>
<q-page class="main-row-panes">
<progress-dialog />

<!-- TODO: 複数エンジン対応 -->
<div
v-if="!isCompletedInitialStartup || allEngineState === 'STARTING'"
Expand Down Expand Up @@ -184,6 +186,7 @@ import AcceptRetrieveTelemetryDialog from "@/components/AcceptRetrieveTelemetryD
import AcceptTermsDialog from "@/components/AcceptTermsDialog.vue";
import DictionaryManageDialog from "@/components/DictionaryManageDialog.vue";
import EngineManageDialog from "@/components/EngineManageDialog.vue";
import ProgressDialog from "@/components/ProgressDialog.vue";
import { AudioItem, EngineState } from "@/store/type";
import { QResizeObserver, useQuasar } from "quasar";
import path from "path";
Expand Down Expand Up @@ -215,6 +218,7 @@ export default defineComponent({
AcceptTermsDialog,
DictionaryManageDialog,
EngineManageDialog,
ProgressDialog,
},

setup() {
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/store/Vuex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ describe("store/vuex.js test", () => {
confirmedTips: {
tweakableSliderByScroll: false,
},
progress: -1,
progressCount: 0,
},
getters: {
...uiStore.getters,
Expand Down