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

FIX: electron-storeの保存場所をGPU版と統一する #1005

Merged
merged 3 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions public/qAndA.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ VOICEVOX Twitter アカウント [@voicevox_pj](https://twitter.com/voicevox_pj)

#### Windows 版

`C:\Users\(ユーザー名)\AppData\Roaming\voicevox` もしくは `C:\Users\(ユーザー名)\AppData\Roaming\voicevox-cpu`
`C:\Users\(ユーザー名)\AppData\Roaming\voicevox`

#### Mac 版

`/Users/(ユーザー名)/Library/Application Support/voicevox-cpu`
`/Users/(ユーザー名)/Library/Application Support/voicevox`

### Q. エンジンの起動が失敗したというエラーが表示されます。

Expand Down
26 changes: 17 additions & 9 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,32 @@ type SingleInstanceLockData = {
filePath: string | undefined;
};

const isDevelopment = process.env.NODE_ENV !== "production";

// Electronの設定ファイルの保存場所を変更
const fixedUserDataDir = path.join(
app.getPath("appData"),
`voicevox${isDevelopment ? "-dev" : ""}`
);
if (!fs.existsSync(fixedUserDataDir)) {
fs.mkdirSync(fixedUserDataDir);
}
app.setPath("userData", fixedUserDataDir);
Comment on lines +47 to +54
Copy link
Member

Choose a reason for hiding this comment

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

fixedUserDataDirが下1000行のどこかで意図せず使われるかもなので、blockにして使えなくするのとかどうでしょう。

Suggested change
const fixedUserDataDir = path.join(
app.getPath("appData"),
`voicevox${isDevelopment ? "-dev" : ""}`
);
if (!fs.existsSync(fixedUserDataDir)) {
fs.mkdirSync(fixedUserDataDir);
}
app.setPath("userData", fixedUserDataDir);
{
const fixedUserDataDir = path.join(
app.getPath("appData"),
`voicevox${isDevelopment ? "-dev" : ""}`
);
if (!fs.existsSync(fixedUserDataDir)) {
fs.mkdirSync(fixedUserDataDir);
}
app.setPath("userData", fixedUserDataDir);
}
}

あるいは関数化するのも良いかもです。
(そのままでも問題ないです!)


// silly以上のログをコンソールに出力
log.transports.console.format = "[{h}:{i}:{s}.{ms}] [{level}] {text}";
log.transports.console.level = "silly";

// warn以上のログをファイルに出力
const prefix = dayjs().format("YYYYMMDD_HHmmss");
const logPath = app.getPath("logs");
log.transports.file.format = "[{h}:{i}:{s}.{ms}] [{level}] {text}";
log.transports.file.level = "warn";
log.transports.file.fileName = `${prefix}_error.log`;

const isDevelopment = process.env.NODE_ENV !== "production";

if (isDevelopment) {
app.setPath(
"userData",
path.join(app.getPath("appData"), `${app.getName()}-dev`)
);
}
log.transports.file.resolvePath = (variables) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return path.join(logPath, variables.fileName!);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

electron-logのドキュメントにはElectronの保存場所を使用する場合は次のコードを使うように書かれているが

return path.join(variables.electronDefaultDir, variables.fileName);

https://github.com/megahertz/electron-log/blob/v4.4.1/docs/file.md#resolvepath-variables-pathvariables-message-logmessage--string
electron-logをインポートした時点で設定されていた値が使われるようなので現在のコードになっている。

};

let win: BrowserWindow;

Expand Down