implement bg presets

This commit is contained in:
sawka 2024-07-30 23:22:41 -07:00
parent ec94bd51f6
commit 8456c57bc1
3 changed files with 91 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import { clsx } from "clsx";
import * as React from "react"; import * as React from "react";
import { forwardRef, useEffect, useRef, useState } from "react"; import { forwardRef, useEffect, useRef, useState } from "react";
import { atoms, globalStore } from "@/app/store/global";
import "./tab.less"; import "./tab.less";
interface TabProps { interface TabProps {
@ -110,8 +111,38 @@ const Tab = React.memo(
function handleContextMenu(e: React.MouseEvent<HTMLDivElement, MouseEvent>) { function handleContextMenu(e: React.MouseEvent<HTMLDivElement, MouseEvent>) {
e.preventDefault(); e.preventDefault();
let menu: ContextMenuItem[] = []; let menu: ContextMenuItem[] = [];
const settings = globalStore.get(atoms.settingsConfigAtom);
console.log("settings", settings);
const bgPresets: string[] = [];
for (const key in settings?.presets ?? {}) {
if (key.startsWith("bg@")) {
bgPresets.push(key);
}
}
bgPresets.sort((a, b) => {
const aOrder = settings.presets[a]["display:order"] ?? 0;
const bOrder = settings.presets[b]["display:order"] ?? 0;
return aOrder - bOrder;
});
console.log("bgPresets", bgPresets);
menu.push({ label: "Copy TabId", click: () => navigator.clipboard.writeText(id) }); menu.push({ label: "Copy TabId", click: () => navigator.clipboard.writeText(id) });
menu.push({ type: "separator" }); menu.push({ type: "separator" });
if (bgPresets.length > 0) {
const submenu: ContextMenuItem[] = [];
const oref = WOS.makeORef("tab", id);
for (const presetName of bgPresets) {
const preset = settings.presets[presetName];
if (preset == null) {
continue;
}
submenu.push({
label: preset["display:name"] ?? presetName,
click: () => services.ObjectService.UpdateObjectMeta(oref, preset),
});
}
menu.push({ label: "Backgrounds", type: "submenu", submenu });
menu.push({ type: "separator" });
}
menu.push({ label: "Close Tab", click: () => onClose(null) }); menu.push({ label: "Close Tab", click: () => onClose(null) });
ContextMenuModel.showContextMenu(menu, e); ContextMenuModel.showContextMenu(menu, e);
} }

View File

@ -179,6 +179,41 @@ var CampbellTheme = TermThemeType{
CursorAccent: "#CCCCCC", // Foreground (used for cursor accent) CursorAccent: "#CCCCCC", // Foreground (used for cursor accent)
} }
var BgDefaultPreset = waveobj.MetaMapType{
wstore.MetaKey_DisplayName: "Default",
wstore.MetaKey_DisplayOrder: -1,
wstore.MetaKey_BgClear: true,
}
var BgRainbowPreset = waveobj.MetaMapType{
wstore.MetaKey_DisplayName: "Rainbow",
wstore.MetaKey_DisplayOrder: 1,
wstore.MetaKey_BgClear: true,
wstore.MetaKey_Bg: "linear-gradient( 226.4deg, rgba(255,26,1,1) 28.9%, rgba(254,155,1,1) 33%, rgba(255,241,0,1) 48.6%, rgba(34,218,1,1) 65.3%, rgba(0,141,254,1) 80.6%, rgba(113,63,254,1) 100.1% );",
wstore.MetaKey_BgOpacity: 0.3,
}
var BgGreenPreset = waveobj.MetaMapType{
wstore.MetaKey_DisplayName: "Green",
wstore.MetaKey_BgClear: true,
wstore.MetaKey_Bg: "green",
wstore.MetaKey_BgOpacity: 0.3,
}
var BgBluePreset = waveobj.MetaMapType{
wstore.MetaKey_DisplayName: "Blue",
wstore.MetaKey_BgClear: true,
wstore.MetaKey_Bg: "blue",
wstore.MetaKey_BgOpacity: 0.3,
}
var BgRedPreset = waveobj.MetaMapType{
wstore.MetaKey_DisplayName: "Red",
wstore.MetaKey_BgClear: true,
wstore.MetaKey_Bg: "red",
wstore.MetaKey_BgOpacity: 0.3,
}
func applyDefaultSettings(settings *SettingsConfigType) { func applyDefaultSettings(settings *SettingsConfigType) {
defaultMimeTypes := map[string]MimeTypeConfigType{ defaultMimeTypes := map[string]MimeTypeConfigType{
"audio": {Icon: "file-audio"}, "audio": {Icon: "file-audio"},
@ -285,4 +320,22 @@ func applyDefaultSettings(settings *SettingsConfigType) {
if _, found := settings.TermThemes["campbell"]; !found { if _, found := settings.TermThemes["campbell"]; !found {
settings.TermThemes["campbell"] = CampbellTheme settings.TermThemes["campbell"] = CampbellTheme
} }
if settings.Presets == nil {
settings.Presets = make(map[string]*waveobj.MetaMapType)
}
if _, found := settings.Presets["bg@default"]; !found {
settings.Presets["bg@default"] = &BgDefaultPreset
}
if _, found := settings.Presets["bg@rainbow"]; !found {
settings.Presets["bg@rainbow"] = &BgRainbowPreset
}
if _, found := settings.Presets["bg@green"]; !found {
settings.Presets["bg@green"] = &BgGreenPreset
}
if _, found := settings.Presets["bg@blue"]; !found {
settings.Presets["bg@blue"] = &BgBluePreset
}
if _, found := settings.Presets["bg@red"]; !found {
settings.Presets["bg@red"] = &BgRedPreset
}
} }

View File

@ -18,6 +18,9 @@ type MetaMapType = waveobj.MetaMapType
// TODO: will code generate one side of this so we don't need to add the keys in two places // TODO: will code generate one side of this so we don't need to add the keys in two places
// will probably drive this off the meta decls so we can add more information and validate the keys/values // will probably drive this off the meta decls so we can add more information and validate the keys/values
const ( const (
MetaKey_DisplayName = "display:name" // special, does not get merged
MetaKey_DisplayOrder = "display:order" // special, does not get merged
MetaKey_View = "view" MetaKey_View = "view"
MetaKey_Controller = "controller" MetaKey_Controller = "controller"
MetaKey_Title = "title" MetaKey_Title = "title"
@ -43,6 +46,7 @@ const (
MetaKey_CmdNoWsh = "cmd:nowsh" MetaKey_CmdNoWsh = "cmd:nowsh"
MetaKey_Bg = "bg" MetaKey_Bg = "bg"
MetaKey_BgClear = "bg:*"
MetaKey_BgOpacity = "bg:opacity" MetaKey_BgOpacity = "bg:opacity"
MetaKey_BgBlendMode = "bg:blendmode" MetaKey_BgBlendMode = "bg:blendmode"
@ -140,6 +144,9 @@ func MergeMeta(meta MetaMapType, metaUpdate MetaMapType) MetaMapType {
} }
// now deal with regular keys // now deal with regular keys
for k, v := range metaUpdate { for k, v := range metaUpdate {
if strings.HasPrefix(k, "display:") {
continue
}
if strings.HasSuffix(k, ":*") { if strings.HasSuffix(k, ":*") {
continue continue
} }