Skip to content
Merged
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
8 changes: 6 additions & 2 deletions src/renderer/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import packageJson from "../../../package.json";

const APP_VERSION = packageJson?.version || "0.0.0";
Comment on lines +1 to +3

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

package.json を直接インポートしてバージョンを取得する方法は機能しますが、いくつか改善の余地があります。この方法はレンダラープロセスとプロジェクトのファイル構造を密結合させてしまいます。

Electron開発で推奨されるより堅牢なアプローチは、メインプロセスで app.getVersion() API を使用してバージョン番号を取得し、それをプリロードスクリプトを介してレンダラープロセスに安全に公開することです。

このアプローチの利点:

  • 関心の分離: レンダラーはバージョンの取得方法を意識する必要がなくなります。
  • 堅牢性: プロジェクトのファイル構造が変更されても、このコードは影響を受けません。
  • バンドルサイズ: package.json ファイル全体がレンダラーのバンドルに含まれるのを防ぎます(この場合、影響は小さいですが)。

この変更は現在のプルリクエストの範囲を超える可能性があるため、必須の修正ではありません。しかし、将来のメンテナンス性を向上させるために、リファクタリングの機会に検討する価値があるでしょう。


export type Language = "en" | "ja";

type Dictionary = Record<string, string>;

const en: Dictionary = {
// Generic
"App Title": "SwitchBot Client",
"Footer Version": "SwitchBot PC Client v0.0.1",
"Footer Version": `SwitchBot PC Client v${APP_VERSION}`,
Devices: "Devices",
Settings: "Settings",
Theme: "Theme",
Expand Down Expand Up @@ -125,7 +129,7 @@ const en: Dictionary = {
const ja: Dictionary = {
// Generic
"App Title": "SwitchBot クライアント",
"Footer Version": "SwitchBot PC クライアント v0.0.1",
"Footer Version": `SwitchBot PC クライアント v${APP_VERSION}`,
Devices: "デバイス",
Settings: "設定",
Theme: "テーマ",
Expand Down