Skip to content

Commit

Permalink
設定値を増やすときの手間を減らす
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba committed Jan 7, 2024
1 parent 7ddfaeb commit 8884d35
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 226 deletions.
30 changes: 21 additions & 9 deletions src/components/SettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1041,18 +1041,25 @@ const availableThemeNameComputed = computed(() => {
const editorFont = computed(() => store.state.editorFont);
const changeEditorFont = (editorFont: EditorFontType) => {
store.dispatch("SET_EDITOR_FONT", { editorFont });
store.dispatch("SET_ROOT_MISC_SETTING", {
key: "editorFont",
value: editorFont,
});
};
const enableMultiEngine = computed(() => store.state.enableMultiEngine);
const setEnableMultiEngine = (enableMultiEngine: boolean) => {
store.dispatch("SET_ENABLE_MULTI_ENGINE", { enableMultiEngine });
store.dispatch("SET_ROOT_MISC_SETTING", {
key: "enableMultiEngine",
value: enableMultiEngine,
});
};
const showTextLineNumber = computed(() => store.state.showTextLineNumber);
const changeShowTextLineNumber = (showTextLineNumber: boolean) => {
store.dispatch("SET_SHOW_TEXT_LINE_NUMBER", {
showTextLineNumber,
store.dispatch("SET_ROOT_MISC_SETTING", {
key: "showTextLineNumber",
value: showTextLineNumber,
});
};
Expand All @@ -1063,8 +1070,9 @@ const showAddAudioItemButton = computed(
const changeShowAddAudioItemButton = async (
showAddAudioItemButton: boolean
) => {
store.dispatch("SET_SHOW_ADD_AUDIO_ITEM_BUTTON", {
showAddAudioItemButton,
store.dispatch("SET_ROOT_MISC_SETTING", {
key: "showAddAudioItemButton",
value: showAddAudioItemButton,
});
// 設定をオフにする場合はヒントを表示
Expand All @@ -1076,8 +1084,9 @@ const changeShowAddAudioItemButton = async (
});
if (result === "CANCEL") {
// キャンセルしたら設定を元に戻す
store.dispatch("SET_SHOW_ADD_AUDIO_ITEM_BUTTON", {
showAddAudioItemButton: true,
store.dispatch("SET_ROOT_MISC_SETTING", {
key: "showAddAudioItemButton",
value: true,
});
}
}
Expand Down Expand Up @@ -1272,7 +1281,10 @@ const splitTextWhenPaste = computed(() => store.state.splitTextWhenPaste);
const changeSplitTextWhenPaste = (
splitTextWhenPaste: SplitTextWhenPasteType
) => {
store.dispatch("SET_SPLIT_TEXT_WHEN_PASTE", { splitTextWhenPaste });
store.dispatch("SET_ROOT_MISC_SETTING", {
key: "splitTextWhenPaste",
value: splitTextWhenPaste,
});
};
const showsFilePatternEditDialog = ref(false);
Expand Down
138 changes: 40 additions & 98 deletions src/store/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import {
ToolbarSetting,
EngineId,
ConfirmedTips,
RootMiscSetting as RootMiscSetting,
} from "@/type/preload";
import { IsEqual } from "@/type/utility";

const hotkeyFunctionCache: Record<string, () => HotkeyReturnType> = {};

Expand Down Expand Up @@ -89,22 +91,6 @@ export const settingStore = createPartialStore<SettingStoreTypes>({
});
}

dispatch("SET_EDITOR_FONT", {
editorFont: await window.electron.getSetting("editorFont"),
});

dispatch("SET_SHOW_TEXT_LINE_NUMBER", {
showTextLineNumber: await window.electron.getSetting(
"showTextLineNumber"
),
});

dispatch("SET_SHOW_ADD_AUDIO_ITEM_BUTTON", {
showAddAudioItemButton: await window.electron.getSetting(
"showAddAudioItemButton"
),
});

dispatch("SET_ACCEPT_RETRIEVE_TELEMETRY", {
acceptRetrieveTelemetry: await window.electron.getSetting(
"acceptRetrieveTelemetry"
Expand All @@ -129,16 +115,6 @@ export const settingStore = createPartialStore<SettingStoreTypes>({
),
});

commit("SET_SPLIT_TEXT_WHEN_PASTE", {
splitTextWhenPaste: await window.electron.getSetting(
"splitTextWhenPaste"
),
});

commit("SET_SPLITTER_POSITION", {
splitterPosition: await window.electron.getSetting("splitterPosition"),
});

commit("SET_CONFIRMED_TIPS", {
confirmedTips: await window.electron.getSetting("confirmedTips"),
});
Expand All @@ -157,11 +133,30 @@ export const settingStore = createPartialStore<SettingStoreTypes>({
});
}

commit("SET_ENABLE_MULTI_ENGINE", {
enableMultiEngine: await window.electron.getSetting(
"enableMultiEngine"
),
});
const rootMiscSettingKeys = [
"editorFont",
"showTextLineNumber",
"showAddAudioItemButton",
"splitTextWhenPaste",
"splitterPosition",
"enableMultiEngine",
] as const;

// rootMiscSettingKeysに値を足し忘れていたときに型エラーを出す検出用コード
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _: IsEqual<
keyof RootMiscSetting,
typeof rootMiscSettingKeys[number]
> = true;

for (const key of rootMiscSettingKeys) {
commit("SET_ROOT_MISC_SETTING", {
// NOTE: Vuexの型処理でUnionが解かれてしまうのを迂回している
// FIXME: このワークアラウンドをなくす
key: key as never,
value: await window.electron.getSetting(key),
});
}
},
},

Expand Down Expand Up @@ -225,6 +220,20 @@ export const settingStore = createPartialStore<SettingStoreTypes>({
},
},

SET_ROOT_MISC_SETTING: {
mutation(state, { key, value }) {
// NOTE: Vuexの型処理でUnionが解かれてしまうのを迂回している
// FIXME: このワークアラウンドをなくす
state[key as never] = value;
},
action({ commit }, { key, value }) {
window.electron.setSetting(key, value);
// NOTE: Vuexの型処理でUnionが解かれてしまうのを迂回している
// FIXME: このワークアラウンドをなくす
commit("SET_ROOT_MISC_SETTING", { key: key as never, value });
},
},

SET_THEME_SETTING: {
mutation(
state,
Expand Down Expand Up @@ -285,43 +294,6 @@ export const settingStore = createPartialStore<SettingStoreTypes>({
},
},

SET_EDITOR_FONT: {
mutation(state, { editorFont }) {
state.editorFont = editorFont;
},
action({ commit }, { editorFont }) {
window.electron.setSetting("editorFont", editorFont);
commit("SET_EDITOR_FONT", { editorFont });
},
},

SET_SHOW_TEXT_LINE_NUMBER: {
mutation(state, { showTextLineNumber }) {
state.showTextLineNumber = showTextLineNumber;
},
action({ commit }, { showTextLineNumber }) {
window.electron.setSetting("showTextLineNumber", showTextLineNumber);
commit("SET_SHOW_TEXT_LINE_NUMBER", {
showTextLineNumber,
});
},
},

SET_SHOW_ADD_AUDIO_ITEM_BUTTON: {
mutation(state, { showAddAudioItemButton }) {
state.showAddAudioItemButton = showAddAudioItemButton;
},
action({ commit }, { showAddAudioItemButton }) {
window.electron.setSetting(
"showAddAudioItemButton",
showAddAudioItemButton
);
commit("SET_SHOW_ADD_AUDIO_ITEM_BUTTON", {
showAddAudioItemButton,
});
},
},

SET_ACCEPT_RETRIEVE_TELEMETRY: {
mutation(state, { acceptRetrieveTelemetry }) {
state.acceptRetrieveTelemetry = acceptRetrieveTelemetry;
Expand Down Expand Up @@ -366,26 +338,6 @@ export const settingStore = createPartialStore<SettingStoreTypes>({
},
},

SET_SPLIT_TEXT_WHEN_PASTE: {
mutation(state, { splitTextWhenPaste }) {
state.splitTextWhenPaste = splitTextWhenPaste;
},
action({ commit }, { splitTextWhenPaste }) {
window.electron.setSetting("splitTextWhenPaste", splitTextWhenPaste);
commit("SET_SPLIT_TEXT_WHEN_PASTE", { splitTextWhenPaste });
},
},

SET_SPLITTER_POSITION: {
mutation(state, { splitterPosition }) {
state.splitterPosition = splitterPosition;
},
action({ commit }, { splitterPosition }) {
window.electron.setSetting("splitterPosition", splitterPosition);
commit("SET_SPLITTER_POSITION", { splitterPosition });
},
},

SET_CONFIRMED_TIPS: {
mutation(state, { confirmedTips }) {
state.confirmedTips = confirmedTips;
Expand Down Expand Up @@ -436,16 +388,6 @@ export const settingStore = createPartialStore<SettingStoreTypes>({
},
},

SET_ENABLE_MULTI_ENGINE: {
mutation(state, { enableMultiEngine }) {
state.enableMultiEngine = enableMultiEngine;
},
action({ commit }, { enableMultiEngine }) {
window.electron.setSetting("enableMultiEngine", enableMultiEngine);
commit("SET_ENABLE_MULTI_ENGINE", { enableMultiEngine });
},
},

CHANGE_USE_GPU: {
/**
* CPU/GPUモードを切り替えようとする。
Expand Down
55 changes: 15 additions & 40 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ import {
MorphingInfo,
ActivePointScrollMode,
EngineInfo,
SplitTextWhenPasteType,
SplitterPosition,
ConfirmedTips,
EngineDirValidationResult,
EditorFontType,
EngineSettings,
MorphableTargetInfoTable,
EngineSetting,
Expand All @@ -48,6 +45,7 @@ import {
StyleId,
AudioKey,
PresetKey,
RootMiscSetting,
} from "@/type/preload";
import { IEngineConnectorFactory } from "@/infrastructures/EngineConnector";
import {
Expand Down Expand Up @@ -1040,17 +1038,19 @@ export type SettingStoreState = {
engineInfos: Record<EngineId, EngineInfo>;
engineManifests: Record<EngineId, EngineManifest>;
themeSetting: ThemeSetting;
editorFont: EditorFontType;
showTextLineNumber: boolean;
showAddAudioItemButton: boolean;
acceptRetrieveTelemetry: AcceptRetrieveTelemetryStatus;
experimentalSetting: ExperimentalSetting;
splitTextWhenPaste: SplitTextWhenPasteType;
splitterPosition: SplitterPosition;
confirmedTips: ConfirmedTips;
engineSettings: EngineSettings;
enableMultiEngine: boolean;
};
} & RootMiscSetting;

// keyとvalueの型を連動するようにしたPayloadを作る
type KeyValuePayload<R, K extends keyof R = keyof R> = K extends keyof R
? {
key: K;
value: R[K];
}
: never;

export type SettingStoreTypes = {
HYDRATE_SETTING_STORE: {
Expand All @@ -1072,26 +1072,16 @@ export type SettingStoreTypes = {
action(payload: { data: ToolbarSetting }): void;
};

SET_ROOT_MISC_SETTING: {
mutation: KeyValuePayload<RootMiscSetting>;
action(payload: KeyValuePayload<RootMiscSetting>): void;
};

SET_THEME_SETTING: {
mutation: { currentTheme: string; themes?: ThemeConf[] };
action(payload: { currentTheme: string }): void;
};

SET_EDITOR_FONT: {
mutation: { editorFont: EditorFontType };
action(payload: { editorFont: EditorFontType }): void;
};

SET_SHOW_TEXT_LINE_NUMBER: {
mutation: { showTextLineNumber: boolean };
action(payload: { showTextLineNumber: boolean }): void;
};

SET_SHOW_ADD_AUDIO_ITEM_BUTTON: {
mutation: { showAddAudioItemButton: boolean };
action(payload: { showAddAudioItemButton: boolean }): void;
};

SET_ACCEPT_RETRIEVE_TELEMETRY: {
mutation: { acceptRetrieveTelemetry: AcceptRetrieveTelemetryStatus };
action(payload: {
Expand All @@ -1109,16 +1099,6 @@ export type SettingStoreTypes = {
action(payload: { experimentalSetting: ExperimentalSetting }): void;
};

SET_SPLIT_TEXT_WHEN_PASTE: {
mutation: { splitTextWhenPaste: SplitTextWhenPasteType };
action(payload: { splitTextWhenPaste: SplitTextWhenPasteType }): void;
};

SET_SPLITTER_POSITION: {
mutation: { splitterPosition: SplitterPosition };
action(payload: { splitterPosition: SplitterPosition }): void;
};

SET_CONFIRMED_TIPS: {
mutation: { confirmedTips: ConfirmedTips };
action(payload: { confirmedTips: ConfirmedTips }): void;
Expand All @@ -1140,11 +1120,6 @@ export type SettingStoreTypes = {
}): Promise<void>;
};

SET_ENABLE_MULTI_ENGINE: {
mutation: { enableMultiEngine: boolean };
action(payload: { enableMultiEngine: boolean }): void;
};

CHANGE_USE_GPU: {
action(payload: { useGpu: boolean; engineId: EngineId }): Promise<void>;
};
Expand Down
Loading

0 comments on commit 8884d35

Please sign in to comment.