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
6 changes: 6 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -28,6 +28,12 @@ export default defineComponent({
watch(query, (newQuery) => {
if (newQuery) {
store.dispatch("SET_IS_SAFE_MODE", newQuery["isSafeMode"] === "true");
const filePath = newQuery["projectFilePath"];
if (typeof filePath === "string" && filePath !== "") {
store.commit("SET_PROJECT_FILEPATH", {
filePath,
});
}
}
});

57 changes: 30 additions & 27 deletions src/background.ts
Original file line number Diff line number Diff line change
@@ -342,15 +342,43 @@ async function createWindow() {
icon: path.join(__static, "icon.png"),
});

let projectFilePath = "";
sabonerune marked this conversation as resolved.
Show resolved Hide resolved
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周りを弄るのが怖いので一旦このままにしておきます


if (process.env.WEBPACK_DEV_SERVER_URL) {
await win.loadURL(
(process.env.WEBPACK_DEV_SERVER_URL as string) +
"#/home?isSafeMode=" +
appState.isSafeMode
appState.isSafeMode +
"&projectFilePath=" +
projectFilePath
);
} else {
createProtocol("app");
win.loadURL("app://./index.html#/home?isSafeMode=" + appState.isSafeMode);
win.loadURL(
"app://./index.html#/home?isSafeMode=" +
appState.isSafeMode +
"&projectFilePath=" +
projectFilePath
);
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
}
if (isDevelopment) win.webContents.openDevTools();

@@ -383,31 +411,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);
}

13 changes: 9 additions & 4 deletions src/views/EditorHome.vue
Original file line number Diff line number Diff line change
@@ -540,11 +540,16 @@ export default defineComponent({
// 辞書を同期
await store.dispatch("SYNC_ALL_USER_DICT");

const projectFilePath = store.state.projectFilePath;
if (projectFilePath != undefined) {
// プロジェクトファイルの読み込みに失敗したときのために事前にprojectFilePathをundefinedにしておく
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
store.commit("SET_PROJECT_FILEPATH", { filePath: undefined });
await store.dispatch("LOAD_PROJECT_FILE", {
filePath: projectFilePath,
});
}
// 最初のAudioCellを作成
const audioItem: AudioItem = await store.dispatch(
"GENERATE_AUDIO_ITEM",
{}
);
const audioItem = await store.dispatch("GENERATE_AUDIO_ITEM", {});
const newAudioKey = await store.dispatch("REGISTER_AUDIO_ITEM", {
audioItem,
});