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

ENH: プロジェクトファイルをエンジンが起動した後に読み込まれるようにする #1147

Merged
merged 9 commits into from
Feb 2, 2023
61 changes: 29 additions & 32 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Comment on lines +420 to +438
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここロジック綺麗にできそうだなと思いました。
Macだったとき・そうじゃないときでfilePathを先に作って、後ろで

      if (
        fs.existsSync(filePath) &&
        fs.statSync(filePath).isFile() &&
        filePath.endsWith(".vvproj")
      ) {
        projectFilePath = encodeURI(filePath);
      }

する感じを想像しています。

(コード移した感じなので修正は気が向いたらで十分かなと!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ちょっとMac周りを弄るのが怖いので一旦このままにしておきます


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();

Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const routes: Array<RouteRecordRaw> = [
{
path: "/home",
component: EditorHome,
props: (route) => ({ projectFilePath: route.query["projectFilePath"] }),
},
];

Expand Down
9 changes: 7 additions & 2 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
},

LOAD_PROJECT_FILE: {
/**
* プロジェクトファイルを読み込む。読み込めたかの成否が返る。
*/
action: createUILockAction(
async (
context,
Expand All @@ -75,7 +78,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
title: "プロジェクトファイルの選択",
});
if (ret == undefined || ret?.length == 0) {
return;
return false;
}
filePath = ret[0];
}
Expand Down Expand Up @@ -275,7 +278,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
cancelId: 1,
});
if (result == 1) {
return;
return false;
}
}
await context.dispatch("REMOVE_ALL_AUDIO_ITEM");
Expand All @@ -293,6 +296,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
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 = (() => {
Expand All @@ -307,6 +311,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
title: "エラー",
message,
});
return false;
}
}
),
Expand Down
2 changes: 1 addition & 1 deletion src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
45 changes: 28 additions & 17 deletions src/views/EditorHome.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ import cloneDeep from "clone-deep";
export default defineComponent({
name: "EditorHome",

props: {
projectFilePath: { type: String },
},

components: {
draggable,
MenuBar,
Expand All @@ -227,7 +231,7 @@ export default defineComponent({
ProgressDialog,
},

setup() {
setup(props) {
const store = useStore();
const $q = useQuasar();

Expand Down Expand Up @@ -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);

Expand Down