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

ダイアログをQuasarのものに置き換える #2286

Merged
merged 32 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4159c46
Add: ブラウザ版にダイアログを追加
sevenc-nanashi Oct 8, 2024
77aab3a
Add: Storybookを追加
sevenc-nanashi Oct 8, 2024
524f454
Change: 既存のものを新しいダイアログを使う用にする
sevenc-nanashi Oct 9, 2024
cf487e2
Add: テストを追加
sevenc-nanashi Oct 9, 2024
bedeb98
Improve: テキストを良い感じにする
sevenc-nanashi Oct 9, 2024
564156b
Delete: 使われていないpropsを削除
sevenc-nanashi Oct 9, 2024
90e9c42
Fix: テストを修正
sevenc-nanashi Oct 9, 2024
4bb8647
Merge: main -> add/browser-dialog
sevenc-nanashi Oct 13, 2024
0a6687b
Fix: package-lock.jsonを再構築
sevenc-nanashi Oct 13, 2024
b6afa6b
Fix: テストが落ちてるのを修正
sevenc-nanashi Oct 13, 2024
e790b61
Add: 複数行できるように
sevenc-nanashi Oct 16, 2024
5792b2d
Merge: upstream/main -> add/browser-dialog
sevenc-nanashi Oct 16, 2024
29b9328
(CI用)
sevenc-nanashi Oct 16, 2024
67e10a7
(スナップショットを更新)
github-actions[bot] Oct 16, 2024
e6ee86f
Code: 空行を空ける
sevenc-nanashi Oct 16, 2024
80cb962
Code: 空行を空ける(その2)
sevenc-nanashi Oct 16, 2024
0b61d22
Code: TODOを追加
sevenc-nanashi Oct 16, 2024
1d0e534
Code: コメントを追加
sevenc-nanashi Oct 19, 2024
26e41b1
Delete: backendのアラート周りを爆破
sevenc-nanashi Oct 19, 2024
f7c53fa
Code: Lintのエラーを修正
sevenc-nanashi Oct 19, 2024
e217e92
Merge: upstream/main -> add/browser-dialog
sevenc-nanashi Oct 19, 2024
1d21395
Update: Storyを更新
sevenc-nanashi Oct 19, 2024
f76d481
Fix: イベント名を修正
sevenc-nanashi Oct 19, 2024
8ba6947
Fix: waitForを使う
sevenc-nanashi Oct 19, 2024
71e78c0
Fix: onUpdateを監視する
sevenc-nanashi Oct 19, 2024
f5db398
Revert: デフォルトを戻す
sevenc-nanashi Oct 19, 2024
d03ee90
Code: コメントを更新
sevenc-nanashi Oct 19, 2024
9d98019
Fix: 条件の反転を修正
sevenc-nanashi Oct 19, 2024
e21e618
Code: コメントを更新
sevenc-nanashi Oct 19, 2024
71b7273
Code: 型の名前を変更
sevenc-nanashi Oct 19, 2024
833d85e
Code: フォーマット
sevenc-nanashi Oct 19, 2024
5e6632d
Change: onHideを監視する
sevenc-nanashi Oct 19, 2024
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
943 changes: 249 additions & 694 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"shlex": "2.1.2",
"systeminformation": "5.21.15",
"tree-kill": "1.2.2",
"vue": "3.4.26",
"vue": "3.5.11",
"vuedraggable": "4.1.0",
"vuex": "4.0.2",
"zod": "3.22.4"
Expand Down Expand Up @@ -99,7 +99,7 @@
"@typescript-eslint/parser": "7.15.0",
"@typescript-eslint/types": "7.15.0",
"@typescript-eslint/utils": "7.15.0",
"@vitejs/plugin-vue": "5.0.4",
"@vitejs/plugin-vue": "5.1.4",
"@vitest/browser": "2.1.2",
"@vitest/ui": "2.1.2",
"@voicevox/eslint-plugin": "file:./eslint-plugin",
Expand Down Expand Up @@ -128,12 +128,12 @@
"ts-node": "10.9.1",
"typescript": "5.5.2",
"vite": "5.3.2",
"vite-plugin-checker": "0.7.0",
"vite-plugin-checker": "0.8.0",
"vite-plugin-electron": "0.28.4",
"vite-plugin-node-polyfills": "0.21.0",
"vite-tsconfig-paths": "4.2.1",
"vitest": "2.1.2",
"vue-tsc": "2.0.24",
"vue-tsc": "2.1.6",
"yargs": "17.2.1"
}
}
25 changes: 0 additions & 25 deletions src/backend/browser/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
writeFileImpl,
} from "./fileImpl";
import { getConfigManager } from "./browserConfig";

import { IpcSOData } from "@/type/ipc";
import {
defaultHotkeySettings,
Expand Down Expand Up @@ -142,30 +141,6 @@ export const api: Sandbox = {
],
});
},
showMessageDialog(obj: {
type: "none" | "info" | "error" | "question" | "warning";
title: string;
message: string;
}) {
window.alert(`${obj.title}\n${obj.message}`);
// NOTE: どの呼び出し元も、return valueを使用していないので雑に対応している
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return Promise.resolve({} as any);
},
showQuestionDialog(obj: {
type: "none" | "info" | "error" | "question" | "warning";
title: string;
message: string;
buttons: string[];
cancelId?: number;
defaultId?: number;
}) {
// FIXME
// TODO: 例えば動的にdialog要素をDOMに生成して、それを表示させるみたいのはあるかもしれない
throw new Error(
`Not implemented: showQuestionDialog, request: ${JSON.stringify(obj)}`,
);
},
async showImportFileDialog(obj: {
name?: string;
extensions?: string[];
Expand Down
27 changes: 0 additions & 27 deletions src/backend/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,33 +605,6 @@ registerIpcMainHandle<IpcMainHandle>({
return result.filePaths;
},

SHOW_MESSAGE_DIALOG: (_, { type, title, message }) => {
return dialog.showMessageBox(win, {
type,
title,
message,
});
},

SHOW_QUESTION_DIALOG: (
_,
{ type, title, message, buttons, cancelId, defaultId },
) => {
return dialog
.showMessageBox(win, {
type,
buttons,
title,
message,
noLink: true,
cancelId,
defaultId,
})
.then((value) => {
return value.response;
});
},

SHOW_WARNING_DIALOG: (_, { title, message }) => {
return dialog.showMessageBox(win, {
type: "warning",
Expand Down
22 changes: 0 additions & 22 deletions src/backend/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,6 @@ const api: Sandbox = {
return ipcRendererInvokeProxy.SHOW_PROJECT_LOAD_DIALOG({ title });
},

showMessageDialog: ({ type, title, message }) => {
return ipcRendererInvokeProxy.SHOW_MESSAGE_DIALOG({ type, title, message });
},

showQuestionDialog: ({
type,
title,
message,
buttons,
cancelId,
defaultId,
}) => {
return ipcRendererInvokeProxy.SHOW_QUESTION_DIALOG({
type,
title,
message,
buttons,
cancelId,
defaultId,
});
},

showImportFileDialog: ({ title, name, extensions }) => {
return ipcRendererInvokeProxy.SHOW_IMPORT_FILE_DIALOG({
title,
Expand Down
202 changes: 98 additions & 104 deletions src/components/Dialog/Dialog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Dialog, DialogChainObject, Notify, Loading } from "quasar";
import { Dialog, Notify, Loading } from "quasar";
import SaveAllResultDialog from "./SaveAllResultDialog.vue";
import QuestionDialog from "./TextDialog/QuestionDialog.vue";
import MessageDialog from "./TextDialog/MessageDialog.vue";
import { DialogType } from "./TextDialog/common";
import { AudioKey, ConfirmedTips } from "@/type/preload";
import {
AllActions,
Expand All @@ -12,29 +15,35 @@ import { withProgressDotNotation as withProgress } from "@/store/ui";

type MediaType = "audio" | "text";

export type CommonDialogResult = "OK" | "CANCEL";
export type CommonDialogOptions = {
alert: {
title: string;
message: string;
ok?: string;
};
confirm: {
title: string;
message: string;
html?: boolean;
actionName: string;
cancel?: string;
};
warning: {
title: string;
message: string;
actionName: string;
cancel?: string;
};
export type TextDialogResult = "OK" | "CANCEL";
export type AlertDialogOptions = {
type?: DialogType;
title: string;
message: string;
ok?: string;
};
export type ConfirmDialogOptions = {
type?: DialogType;
title: string;
message: string;
actionName: string;
cancel?: string;
};
export type WarningDialogOptions = {
type?: DialogType;
title: string;
message: string;
actionName: string;
cancel?: string;
};
export type QuestionDialogOptions = {
type?: DialogType;
title: string;
message: string;
buttons: string[];
cancel: number;
default?: number;
};
export type CommonDialogType = keyof CommonDialogOptions;
type CommonDialogCallback = (value: CommonDialogResult) => void;

export type NotifyAndNotShowAgainButtonOption = {
message: string;
Expand All @@ -46,99 +55,84 @@ export type NotifyAndNotShowAgainButtonOption = {
export type LoadingScreenOption = { message: string };

// 汎用ダイアログを表示
export const showAlertDialog = async (
options: CommonDialogOptions["alert"],
) => {
export const showAlertDialog = async (options: AlertDialogOptions) => {
options.ok ??= "閉じる";

return new Promise((resolve: CommonDialogCallback) => {
setCommonDialogCallback(
Dialog.create({
title: options.title,
message: options.message,
ok: {
label: options.ok,
flat: true,
textColor: "display",
},
}),
resolve,
);
});
const { promise, resolve } = Promise.withResolvers<void>();
Dialog.create({
component: MessageDialog,
componentProps: {
type: options.type ?? "info",
title: options.title,
message: options.message,
ok: options.ok,
},
}).onOk(() => resolve());

await promise;

return "OK" as const;
};

/**
* htmlフラグを`true`にする場合、外部からの汚染された文字列を`title`や`message`に含めてはいけません。
* see https://quasar.dev/quasar-plugins/dialog#using-html
*/
export const showConfirmDialog = async (
options: CommonDialogOptions["confirm"],
) => {
export const showConfirmDialog = async (options: ConfirmDialogOptions) => {
options.cancel ??= "キャンセル";

return new Promise((resolve: CommonDialogCallback) => {
setCommonDialogCallback(
Dialog.create({
title: options.title,
message: options.message,
persistent: true, // ダイアログ外側押下時・Esc押下時にユーザが設定ができたと思い込むことを防止する
focus: "ok",
html: options.html,
ok: {
flat: true,
label: options.actionName,
textColor: "display",
},
cancel: {
flat: true,
label: options.cancel,
textColor: "display",
},
}),
resolve,
);
});
const { promise, resolve } = Promise.withResolvers<number>();
Dialog.create({
component: QuestionDialog,
componentProps: {
type: options.type ?? "question",
title: options.title,
message: options.message,
buttons: [options.cancel, options.actionName],
default: 1,
},
}).onOk(({ index }: { index: number }) => resolve(index));

const index = await promise;

return index === 1 ? "OK" : "CANCEL";
};

export const showWarningDialog = async (
options: CommonDialogOptions["warning"],
) => {
export const showWarningDialog = async (options: WarningDialogOptions) => {
options.cancel ??= "キャンセル";

return new Promise((resolve: CommonDialogCallback) => {
setCommonDialogCallback(
Dialog.create({
title: options.title,
message: options.message,
persistent: true,
focus: "cancel",
ok: {
label: options.actionName,
flat: true,
textColor: "warning",
},
cancel: {
label: options.cancel,
flat: true,
textColor: "display",
},
}),
resolve,
);
});
const { promise, resolve } = Promise.withResolvers<number>();
Dialog.create({
component: QuestionDialog,
componentProps: {
type: options.type ?? "warning",
title: options.title,
message: options.message,
buttons: [options.cancel, options.actionName],
default: 0,
},
}).onOk(({ index }: { index: number }) => resolve(index));

const index = await promise;

return index === 1 ? "OK" : "CANCEL";
};

const setCommonDialogCallback = (
dialog: DialogChainObject,
resolve: (result: CommonDialogResult) => void,
) => {
return dialog
.onOk(() => {
resolve("OK");
})
.onCancel(() => {
resolve("CANCEL");
});
export const showQuestionDialog = async (options: QuestionDialogOptions) => {
const { promise, resolve } = Promise.withResolvers<number>();
Dialog.create({
component: QuestionDialog,
componentProps: {
type: options.type ?? "question",
title: options.title,
message: options.message,
buttons: options.buttons,
persistent: options.cancel == undefined,
default: options.default,
},
})
.onOk(({ index }: { index: number }) => resolve(index))
.onCancel(() => resolve(options.cancel));

const index = await promise;

return index;
};

export async function generateAndSaveOneAudioWithDialog({
Expand Down
3 changes: 1 addition & 2 deletions src/components/Dialog/HotkeySettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ const setHotkeyDialogOpened = () => {
const resetHotkey = async (action: string) => {
const result = await store.dispatch("SHOW_CONFIRM_DIALOG", {
title: "ショートカットキーを初期値に戻します",
message: `${action}のショートカットキーを初期値に戻します。<br/>本当に戻しますか?`,
html: true,
message: `${action}のショートカットキーを初期値に戻します。\n本当に戻しますか?`,
actionName: "初期値に戻す",
cancel: "初期値に戻さない",
});
Expand Down
5 changes: 0 additions & 5 deletions src/components/Dialog/ImportSongProjectDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,6 @@ const handleCancel = () => {
</script>

<style scoped lang="scss">
.dialog-card {
width: 700px;
max-width: 80vw;
}

.scrollable-area {
overflow-y: auto;
max-height: calc(100vh - 100px - 295px);
Expand Down
Loading
Loading