Skip to content

Commit

Permalink
Change setting key for themeId fixing issue preventing opening older …
Browse files Browse the repository at this point in the history
…version of GB Studio if using a theme plugin. Remove magic strings for theme + locale settings
  • Loading branch information
chrismaltby committed Oct 24, 2024
1 parent 9560f4c commit d443660
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const assetsRoot = path.normalize(`${rootDir}/src/assets`);

export const OFFICIAL_REPO_URL = "https://plugins.gbstudio.dev/repository.json";

// Electron Settings
export const THEME_SETTING_KEY = "themeId";
export const LOCALE_SETTING_KEY = "locale";

const MAX_ACTORS = 20;
const MAX_ACTORS_SMALL = 10;
const MAX_TRIGGERS = 30;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/lang/initElectronL10N.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from "fs";
import glob from "glob";
import Path from "path";
import en from "lang/en.json";
import { localesRoot } from "consts";
import { LOCALE_SETTING_KEY, localesRoot } from "consts";
import { L10NLookup, setL10NData } from "shared/lib/lang/l10n";
import { getGlobalPluginsPath } from "lib/pluginManager/globalPlugins";
import mapValues from "lodash/mapValues";
Expand All @@ -16,7 +16,7 @@ export const locales = glob
.map((path) => Path.basename(path, ".json"));

export const getAppLocale = () => {
const settingsLocale = app && settings.get("locale");
const settingsLocale = app && settings.get(LOCALE_SETTING_KEY);
const systemLocale = app ? app.getLocale() : "en";
return String(settingsLocale || systemLocale);
};
Expand Down
16 changes: 11 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ import confirmEjectEngineDialog from "lib/electron/dialog/confirmEjectEngineDial
import confirmEjectEngineReplaceDialog from "lib/electron/dialog/confirmEjectEngineReplaceDialog";
import ejectEngineToDir from "lib/project/ejectEngineToDir";
import type { ProjectExportType } from "store/features/buildGame/buildGameActions";
import { assetsRoot, buildUUID, projectTemplatesRoot } from "consts";
import {
assetsRoot,
buildUUID,
LOCALE_SETTING_KEY,
projectTemplatesRoot,
THEME_SETTING_KEY,
} from "consts";
import type {
EngineFieldSchema,
SceneTypeSchema,
Expand Down Expand Up @@ -1294,7 +1300,7 @@ ipcMain.handle("debugger:set-watched", (_event, variableIds: string[]) => {
ipcMain.handle("get-l10n-strings", () => getL10NData());

ipcMain.handle("get-theme", () => {
const themeId = ensureString(settings.get("theme"), "");
const themeId = ensureString(settings.get(THEME_SETTING_KEY), "");
return themeManager.getTheme(themeId, nativeTheme.shouldUseDarkColors);
});

Expand Down Expand Up @@ -1985,7 +1991,7 @@ menu.on("projectPlugins", () => {

menu.on("updateTheme", (value) => {
const pluginThemes = themeManager.getPluginThemes();
settings.set("theme", value as JsonValue);
settings.set(THEME_SETTING_KEY, value as JsonValue);
setMenuItemChecked("themeDefault", value === undefined);
setMenuItemChecked("themeLight", value === "light");
setMenuItemChecked("themeDark", value === "dark");
Expand All @@ -1996,7 +2002,7 @@ menu.on("updateTheme", (value) => {
});

menu.on("updateLocale", (value) => {
settings.set("locale", value as JsonValue);
settings.set(LOCALE_SETTING_KEY, value as JsonValue);
setMenuItemChecked("localeDefault", value === undefined);
for (const lang of l10nManager.getSystemL10Ns()) {
setMenuItemChecked(`locale-${lang.id}`, value === lang.id);
Expand Down Expand Up @@ -2070,7 +2076,7 @@ watchGlobalPlugins({
});

const refreshTheme = () => {
const themeId = ensureString(settings.get("theme"), "");
const themeId = ensureString(settings.get(THEME_SETTING_KEY), "");
const theme = themeManager.getTheme(themeId, nativeTheme.shouldUseDarkColors);
sendToSplashWindow("update-theme", theme);
sendToProjectWindow("update-theme", theme);
Expand Down
16 changes: 8 additions & 8 deletions src/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
MenuItemConstructorOptions,
shell,
} from "electron";
import { assetsRoot } from "./consts";
import { assetsRoot, LOCALE_SETTING_KEY, THEME_SETTING_KEY } from "./consts";
import l10n from "shared/lib/lang/l10n";
import { ThemeManager } from "lib/themes/themeManager";
import { L10nManager } from "lib/lang/l10nManager";
Expand Down Expand Up @@ -381,7 +381,7 @@ const buildMenu = async ({ themeManager, l10nManager }: BuildMenuProps) => {
id: "themeDefault",
label: l10n("MENU_THEME_DEFAULT"),
type: "checkbox",
checked: settings.get("theme") === undefined,
checked: settings.get(THEME_SETTING_KEY) === undefined,
click() {
notifyListeners("updateTheme", undefined);
},
Expand All @@ -391,7 +391,7 @@ const buildMenu = async ({ themeManager, l10nManager }: BuildMenuProps) => {
id: "themeLight",
label: l10n("MENU_THEME_LIGHT"),
type: "checkbox",
checked: settings.get("theme") === "light",
checked: settings.get(THEME_SETTING_KEY) === "light",
click() {
notifyListeners("updateTheme", "light");
},
Expand All @@ -400,7 +400,7 @@ const buildMenu = async ({ themeManager, l10nManager }: BuildMenuProps) => {
id: "themeDark",
label: l10n("MENU_THEME_DARK"),
type: "checkbox",
checked: settings.get("theme") === "dark",
checked: settings.get(THEME_SETTING_KEY) === "dark",
click() {
notifyListeners("updateTheme", "dark");
},
Expand All @@ -413,7 +413,7 @@ const buildMenu = async ({ themeManager, l10nManager }: BuildMenuProps) => {
id: `theme-${theme.id}`,
label: theme.name,
type: "checkbox",
checked: settings.get("theme") === theme.id,
checked: settings.get(THEME_SETTING_KEY) === theme.id,
click() {
notifyListeners("updateTheme", theme.id);
},
Expand All @@ -429,7 +429,7 @@ const buildMenu = async ({ themeManager, l10nManager }: BuildMenuProps) => {
id: "localeDefault",
label: l10n("MENU_LANGUAGE_DEFAULT"),
type: "checkbox",
checked: settings.get("locale") === undefined,
checked: settings.get(LOCALE_SETTING_KEY) === undefined,
click() {
notifyListeners("updateLocale", undefined);
},
Expand All @@ -441,7 +441,7 @@ const buildMenu = async ({ themeManager, l10nManager }: BuildMenuProps) => {
id: `locale-${language.id}`,
label: language.name,
type: "checkbox",
checked: settings.get("locale") === language.id,
checked: settings.get(LOCALE_SETTING_KEY) === language.id,
click() {
notifyListeners("updateLocale", language.id);
},
Expand All @@ -455,7 +455,7 @@ const buildMenu = async ({ themeManager, l10nManager }: BuildMenuProps) => {
id: `locale-${language.id}`,
label: language.name,
type: "checkbox",
checked: settings.get("locale") === language.id,
checked: settings.get(LOCALE_SETTING_KEY) === language.id,
click() {
notifyListeners("updateLocale", language.id);
},
Expand Down

0 comments on commit d443660

Please sign in to comment.