diff --git a/frontend/app/tab/tab.tsx b/frontend/app/tab/tab.tsx index 03664f01f..75915e0dc 100644 --- a/frontend/app/tab/tab.tsx +++ b/frontend/app/tab/tab.tsx @@ -9,6 +9,7 @@ import { clsx } from "clsx"; import * as React from "react"; import { forwardRef, useEffect, useRef, useState } from "react"; +import { atoms, globalStore } from "@/app/store/global"; import "./tab.less"; interface TabProps { @@ -110,8 +111,38 @@ const Tab = React.memo( function handleContextMenu(e: React.MouseEvent) { e.preventDefault(); 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({ 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) }); ContextMenuModel.showContextMenu(menu, e); } diff --git a/pkg/wconfig/settingsconfig.go b/pkg/wconfig/settingsconfig.go index b55f51724..818bb9ff8 100644 --- a/pkg/wconfig/settingsconfig.go +++ b/pkg/wconfig/settingsconfig.go @@ -179,6 +179,41 @@ var CampbellTheme = TermThemeType{ 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) { defaultMimeTypes := map[string]MimeTypeConfigType{ "audio": {Icon: "file-audio"}, @@ -285,4 +320,22 @@ func applyDefaultSettings(settings *SettingsConfigType) { if _, found := settings.TermThemes["campbell"]; !found { 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 + } } diff --git a/pkg/wstore/wstore_meta.go b/pkg/wstore/wstore_meta.go index 258050f9f..e8c8b116c 100644 --- a/pkg/wstore/wstore_meta.go +++ b/pkg/wstore/wstore_meta.go @@ -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 // will probably drive this off the meta decls so we can add more information and validate the keys/values const ( + MetaKey_DisplayName = "display:name" // special, does not get merged + MetaKey_DisplayOrder = "display:order" // special, does not get merged + MetaKey_View = "view" MetaKey_Controller = "controller" MetaKey_Title = "title" @@ -43,6 +46,7 @@ const ( MetaKey_CmdNoWsh = "cmd:nowsh" MetaKey_Bg = "bg" + MetaKey_BgClear = "bg:*" MetaKey_BgOpacity = "bg:opacity" MetaKey_BgBlendMode = "bg:blendmode" @@ -140,6 +144,9 @@ func MergeMeta(meta MetaMapType, metaUpdate MetaMapType) MetaMapType { } // now deal with regular keys for k, v := range metaUpdate { + if strings.HasPrefix(k, "display:") { + continue + } if strings.HasSuffix(k, ":*") { continue }