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
58 changes: 29 additions & 29 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,40 @@ 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周りを弄るのが怖いので一旦このままにしておきます


const parameter =
"#/home?isSafeMode=" +
appState.isSafeMode +
"&projectFilePath=" +
projectFilePath;

if (process.env.WEBPACK_DEV_SERVER_URL) {
await win.loadURL(
(process.env.WEBPACK_DEV_SERVER_URL as string) +
"#/home?isSafeMode=" +
appState.isSafeMode
(process.env.WEBPACK_DEV_SERVER_URL as string) + parameter
);
} else {
createProtocol("app");
win.loadURL("app://./index.html#/home?isSafeMode=" + appState.isSafeMode);
win.loadURL("app://./index.html" + parameter);
}
if (isDevelopment) win.webContents.openDevTools();

Expand Down Expand Up @@ -383,31 +408,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
6 changes: 4 additions & 2 deletions src/store/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const projectStore = createPartialStore<ProjectStoreTypes>({
title: "プロジェクトファイルの選択",
});
if (ret == undefined || ret?.length == 0) {
return;
return false;
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
}
filePath = ret[0];
}
Expand Down Expand Up @@ -275,7 +275,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 +293,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 +308,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 @@ -943,7 +943,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
53 changes: 36 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 @@ -517,6 +521,11 @@ export default defineComponent({
// ソフトウェアを初期化
const isCompletedInitialStartup = ref(false);
onMounted(async () => {
const projectFilePath = props.projectFilePath;
if (projectFilePath != undefined && projectFilePath !== "") {
// タイトルバーに読み込み中のプロジェクト名を表示
store.commit("SET_PROJECT_FILEPATH", { filePath: projectFilePath });
}
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved
await store.dispatch("GET_ENGINE_INFOS");

let engineIds: string[];
Expand All @@ -540,23 +549,33 @@ 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,
const generateInitAudioCell = async () => {
// 最初の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,
});
}
};

if (projectFilePath != undefined && projectFilePath !== "") {
const result = await store.dispatch("LOAD_PROJECT_FILE", {
filePath: projectFilePath,
});
if (!result) {
store.commit("SET_PROJECT_FILEPATH", {});
Copy link
Member

Choose a reason for hiding this comment

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

ここもLOAD_PROJECT_FILEが失敗していたらそもそもSET_PROJECT_FILEPATHされないかなと思いました!

await generateInitAudioCell();
}
} else {
await generateInitAudioCell();
}
Hiroshiba marked this conversation as resolved.
Show resolved Hide resolved

// ショートカットキーの設定
Expand Down