diff --git a/src/background.ts b/src/background.ts index 76bd250881..22c3e0156a 100644 --- a/src/background.ts +++ b/src/background.ts @@ -416,18 +416,40 @@ async function createWindow() { icon: path.join(__static, "icon.png"), }); + let projectFilePath: string | undefined = ""; + if (isMac) { + if (filePathOnMac) { + if (filePathOnMac.endsWith(".vvproj")) { + projectFilePath = encodeURI(filePathOnMac); + } + filePathOnMac = undefined; + } + } else { + if (process.argv.length >= 2) { + const filePath = process.argv[1]; + if ( + fs.existsSync(filePath) && + fs.statSync(filePath).isFile() && + filePath.endsWith(".vvproj") + ) { + projectFilePath = encodeURI(filePath); + } + } + } + + const parameter = + "#/home?isMultiEngineOffMode=" + + appState.isMultiEngineOffMode + + "&projectFilePath=" + + projectFilePath; + if (process.env.WEBPACK_DEV_SERVER_URL) { await win.loadURL( - (process.env.WEBPACK_DEV_SERVER_URL as string) + - "#/home?isMultiEngineOffMode=" + - appState.isMultiEngineOffMode + (process.env.WEBPACK_DEV_SERVER_URL as string) + parameter ); } else { createProtocol("app"); - win.loadURL( - "app://./index.html#/home?isMultiEngineOffMode=" + - appState.isMultiEngineOffMode - ); + win.loadURL("app://./index.html" + parameter); } if (isDevelopment) win.webContents.openDevTools(); @@ -460,31 +482,6 @@ async function createWindow() { }); }); - win.webContents.once("did-finish-load", () => { - if (isMac) { - if (filePathOnMac) { - if (filePathOnMac.endsWith(".vvproj")) { - ipcMainSend(win, "LOAD_PROJECT_FILE", { - filePath: filePathOnMac, - confirm: false, - }); - } - filePathOnMac = undefined; - } - } else { - if (process.argv.length >= 2) { - const filePath = process.argv[1]; - if ( - fs.existsSync(filePath) && - fs.statSync(filePath).isFile() && - filePath.endsWith(".vvproj") - ) { - ipcMainSend(win, "LOAD_PROJECT_FILE", { filePath, confirm: false }); - } - } - } - }); - mainWindowState.manage(win); } diff --git a/src/router/index.ts b/src/router/index.ts index af2f37a724..fa7aefe54b 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -10,6 +10,7 @@ const routes: Array = [ { path: "/home", component: EditorHome, + props: (route) => ({ projectFilePath: route.query["projectFilePath"] }), }, ]; diff --git a/src/store/project.ts b/src/store/project.ts index e77a964eaf..f0cb795b1a 100755 --- a/src/store/project.ts +++ b/src/store/project.ts @@ -64,6 +64,9 @@ export const projectStore = createPartialStore({ }, LOAD_PROJECT_FILE: { + /** + * プロジェクトファイルを読み込む。読み込めたかの成否が返る。 + */ action: createUILockAction( async ( context, @@ -75,7 +78,7 @@ export const projectStore = createPartialStore({ title: "プロジェクトファイルの選択", }); if (ret == undefined || ret?.length == 0) { - return; + return false; } filePath = ret[0]; } @@ -275,7 +278,7 @@ export const projectStore = createPartialStore({ cancelId: 1, }); if (result == 1) { - return; + return false; } } await context.dispatch("REMOVE_ALL_AUDIO_ITEM"); @@ -293,6 +296,7 @@ export const projectStore = createPartialStore({ context.commit("SET_PROJECT_FILEPATH", { filePath }); context.commit("SET_SAVED_LAST_COMMAND_UNIX_MILLISEC", null); context.commit("CLEAR_COMMANDS"); + return true; } catch (err) { window.electron.logError(err); const message = (() => { @@ -307,6 +311,7 @@ export const projectStore = createPartialStore({ title: "エラー", message, }); + return false; } } ), diff --git a/src/store/type.ts b/src/store/type.ts index a925089fa3..1a1fecbd7e 100644 --- a/src/store/type.ts +++ b/src/store/type.ts @@ -941,7 +941,7 @@ export type ProjectStoreTypes = { }; LOAD_PROJECT_FILE: { - action(payload: { filePath?: string; confirm?: boolean }): void; + action(payload: { filePath?: string; confirm?: boolean }): boolean; }; SAVE_PROJECT_FILE: { diff --git a/src/views/EditorHome.vue b/src/views/EditorHome.vue index 8e4800b3e9..efc9d7d0cb 100644 --- a/src/views/EditorHome.vue +++ b/src/views/EditorHome.vue @@ -206,6 +206,10 @@ import cloneDeep from "clone-deep"; export default defineComponent({ name: "EditorHome", + props: { + projectFilePath: { type: String }, + }, + components: { draggable, MenuBar, @@ -227,7 +231,7 @@ export default defineComponent({ ProgressDialog, }, - setup() { + setup(props) { const store = useStore(); const $q = useQuasar(); @@ -540,25 +544,32 @@ export default defineComponent({ // 辞書を同期 await store.dispatch("SYNC_ALL_USER_DICT"); - // 最初のAudioCellを作成 - const audioItem: AudioItem = await store.dispatch( - "GENERATE_AUDIO_ITEM", - {} - ); - const newAudioKey = await store.dispatch("REGISTER_AUDIO_ITEM", { - audioItem, - }); - focusCell({ audioKey: newAudioKey }); - - // 最初の話者を初期化 - if (audioItem.engineId != undefined && audioItem.styleId != undefined) { - store.dispatch("SETUP_SPEAKER", { - audioKey: newAudioKey, - engineId: audioItem.engineId, - styleId: audioItem.styleId, + // プロジェクトファイルが指定されていればロード + let projectFileLoaded = false; + if (props.projectFilePath != undefined && props.projectFilePath !== "") { + projectFileLoaded = await store.dispatch("LOAD_PROJECT_FILE", { + filePath: props.projectFilePath, }); } + if (!projectFileLoaded) { + // 最初のAudioCellを作成 + const audioItem = await store.dispatch("GENERATE_AUDIO_ITEM", {}); + const newAudioKey = await store.dispatch("REGISTER_AUDIO_ITEM", { + audioItem, + }); + focusCell({ audioKey: newAudioKey }); + + // 最初の話者を初期化 + if (audioItem.engineId != undefined && audioItem.styleId != undefined) { + store.dispatch("SETUP_SPEAKER", { + audioKey: newAudioKey, + engineId: audioItem.engineId, + styleId: audioItem.styleId, + }); + } + } + // ショートカットキーの設定 document.addEventListener("keydown", disableDefaultUndoRedo);