save work

This commit is contained in:
Red Adaya 2024-04-11 21:55:55 +08:00
parent e5d3db7631
commit 01fb217785
3 changed files with 26 additions and 38 deletions

View File

@ -37,31 +37,36 @@ class TermStyleBlock extends React.Component<{
termTheme: TermThemeType; termTheme: TermThemeType;
}> { }> {
styleRules: OV<string> = mobx.observable.box("", { name: "StyleBlock-styleRules" }); styleRules: OV<string> = mobx.observable.box("", { name: "StyleBlock-styleRules" });
theme: string;
injectedStyleElement: HTMLStyleElement | null = null; injectedStyleElement: HTMLStyleElement | null = null;
componentDidMount(): void {
const { termTheme } = this.props;
Object.keys(termTheme).forEach((themeKey) => {
// this.loadThemeStyles();
});
}
componentDidUpdate(): void { componentDidUpdate(): void {
const { termTheme } = this.props; const { termTheme } = this.props;
const selector = GlobalModel.termThemeScope.get("selector"); console.log("termTheme", termTheme);
const themeKey = GlobalModel.termThemeScope.get("themeKey"); for (const key of Object.keys(termTheme)) {
const reset = GlobalModel.termThemeScope.get("reset"); const selector = this.getSelector(key);
const currTheme = termTheme[themeKey]; if (selector) {
console.log("reset:=========", reset);
if (reset) {
this.removeInjectedStyle(); this.removeInjectedStyle();
} else if (this.theme !== currTheme) { this.loadThemeStyles(selector, termTheme[key]);
this.loadThemeStyles(selector, themeKey); break;
} }
} }
}
getSelector(themeKey: string) {
const session = GlobalModel.getActiveSession();
const activeSessionId = session.sessionId;
const screen = GlobalModel.getActiveScreen();
const activeScreenId = screen.screenId;
if (themeKey == activeScreenId) {
return `.main-content [data-screenid="${activeScreenId}"]`;
} else if (themeKey == activeSessionId) {
return `.main-content [data-sessionid="${activeSessionId}"]`;
} else if (activeSessionId != themeKey || activeScreenId != themeKey) {
return ".main-content";
}
return null;
}
isValidCSSColor(color) { isValidCSSColor(color) {
const element = document.createElement("div"); const element = document.createElement("div");
@ -85,16 +90,9 @@ class TermStyleBlock extends React.Component<{
} }
} }
loadThemeStyles(selector: string, themeKey: string) { loadThemeStyles(selector: string, theme: string) {
const { termTheme } = this.props;
const currTheme = termTheme[themeKey];
console.log("selector:", selector);
console.log("themeKey:", themeKey);
// Inject new style element // Inject new style element
GlobalModel.getTermThemeJson(currTheme) GlobalModel.getTermThemeJson(theme)
.then((termThemeJson) => { .then((termThemeJson) => {
if (termThemeJson && typeof termThemeJson === "object") { if (termThemeJson && typeof termThemeJson === "object") {
const styleProperties = Object.entries(termThemeJson) const styleProperties = Object.entries(termThemeJson)
@ -110,8 +108,6 @@ class TermStyleBlock extends React.Component<{
document.head.appendChild(style); document.head.appendChild(style);
this.injectedStyleElement = style; this.injectedStyleElement = style;
this.theme = currTheme;
console.log("loaded theme styles:", this.styleRules.get()); console.log("loaded theme styles:", this.styleRules.get());
} else { } else {
console.error("termThemeJson is not an object:", termThemeJson); console.error("termThemeJson is not an object:", termThemeJson);

View File

@ -146,7 +146,6 @@ class TabSettings extends React.Component<{ screen: Screen }, {}> {
if (currTheme == theme) { if (currTheme == theme) {
return; return;
} }
GlobalModel.setTermThemeScope(screenId, `.main-content [data-screenid="${screenId}"]`, theme == null);
const prtn = GlobalCommandRunner.setScreenTermTheme(screenId, theme, false); const prtn = GlobalCommandRunner.setScreenTermTheme(screenId, theme, false);
commandRtnHandler(prtn, this.errorMessage); commandRtnHandler(prtn, this.errorMessage);
} }

View File

@ -139,17 +139,10 @@ class Model {
appUpdateStatus = mobx.observable.box(getApi().getAppUpdateStatus(), { appUpdateStatus = mobx.observable.box(getApi().getAppUpdateStatus(), {
name: "appUpdateStatus", name: "appUpdateStatus",
}); });
termThemes: OMap<string, string> = mobx.observable.array([], { termThemes: OMap<string, string> = mobx.observable.array([], {
name: "terminalThemes", name: "terminalThemes",
deep: false, deep: false,
}); });
termThemeScope: OMap<"selector" | "themeKey" | "reset", string> = mobx.observable.map(
{},
{
name: "termThemeSrcEls",
}
);
termRenderVersion: OV<number> = mobx.observable.box(0, { termRenderVersion: OV<number> = mobx.observable.box(0, {
name: "termRenderVersion", name: "termRenderVersion",
}); });