import * as vscode from "vscode" ; import getSettings from "./getSettings" ; type ColorCustomization = { [ key ] : string | undefined ; } | undefined ; const COLOR_CUSTOMIZATIONS = "colorCustomizations" ; const invertHex = ( hex ? ) => { if ( ! hex ) { return ; } return Number ( hex . replace ( "#" , "0x" ) ) > 0xffffff / 2 ? "#000000" : "#ffffff" ; } ; export default async ( color ? ) => { const colorInverted = invertHex ( color ) ; const settings = vscode . workspace . getConfiguration ( "workbench" ) ; const currentColorCustomization = settings . get ( COLOR_CUSTOMIZATIONS ) || { } ; const { tabBorder , titleBackground , activityBarBackground , statusBarBackground , } = getSettings ( ) ; const tabBarBorderColor = color ; const titleBarBackgroundColor = color ; const titleBarForegroundColor = colorInverted ; const activityBarBackgroundColor = color ; const activityBarForegroundColor = colorInverted ; const statusBarBackgroundColor = color ; const statusBarForegroundColor = colorInverted ; const colorCustomization = { ... currentColorCustomization , ... ( tabBorder ? { "tab.activeBorder" : tabBarBorderColor } : { } ) , ... ( titleBackground ? { "titleBar.activeBackground" : titleBarBackgroundColor } : { } ) , ... ( titleBackground ? { "titleBar.activeForeground" : titleBarForegroundColor } : { } ) , ... ( activityBarBackground ? { "activityBar.background" : activityBarBackgroundColor } : { } ) , ... ( activityBarBackground ? { "activityBar.foreground" : activityBarForegroundColor } : { } ) , ... ( statusBarBackground ? { "statusBar.background" : statusBarBackgroundColor } : { } ) , ... ( statusBarBackground ? { "statusBar.foreground" : statusBarForegroundColor } : { } ) , } ; const hasItems = Object . keys ( colorCustomization ) . filter ( ( x ) => ! ! colorCustomization [ x ] ) . length ; settings . update ( COLOR_CUSTOMIZATIONS , hasItems ? colorCustomization : undefined , vscode . ConfigurationTarget . Workspace ) ; } ;