diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-09-04 14:35:39 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-09-04 14:35:39 +0200 |
| commit | cda16a10fc62c58b9a3eebdca6a5a81bc8b64683 (patch) | |
| tree | 2ec2ba14d997dbdbbb08a67273d352c5230c2d29 /Liquid Glass Bezel/BBLiquidGlassBezelInterface.m | |
| parent | 192eddee203348ec85d52e277d59fc2c5ef96664 (diff) | |
Update appearance for cells when style changes
Diffstat (limited to 'Liquid Glass Bezel/BBLiquidGlassBezelInterface.m')
| -rw-r--r-- | Liquid Glass Bezel/BBLiquidGlassBezelInterface.m | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/Liquid Glass Bezel/BBLiquidGlassBezelInterface.m b/Liquid Glass Bezel/BBLiquidGlassBezelInterface.m index 335eacd..1df5f7e 100644 --- a/Liquid Glass Bezel/BBLiquidGlassBezelInterface.m +++ b/Liquid Glass Bezel/BBLiquidGlassBezelInterface.m @@ -7,6 +7,13 @@ @implementation BBLiquidGlassBezelInterface +- (void)dealloc { + // Remove KVO observers + [[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:@"QSLiquidGlassBezelApplyTint"]; + [[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:@"QSAppearance1A"]; + [[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:@"QSAppearance1T"]; +} + - (id)init { return [self initWithWindowNibName:@"BBLiquidGlassBezelInterface"]; } @@ -42,17 +49,52 @@ [theCell setFont:[NSFont systemFontOfSize:11 weight:NSFontWeightLight]]; [theCell setCellRadiusFactor:32]; - [theCell setHighlightColor:[NSColor colorWithRed:1 green:1 blue:1 alpha:.15]]; - [theCell setTextColor:[NSColor textColor]]; + BOOL shouldApplyTint = [[NSUserDefaults standardUserDefaults] boolForKey:@"QSLiquidGlassBezelApplyTint"]; + NSColor *userHighlightColor = [[NSUserDefaults standardUserDefaults] colorForKey:@"QSAppearance1A"]; + NSColor *userTextColor = shouldApplyTint ? [[NSUserDefaults standardUserDefaults] colorForKey:@"QSAppearance1T"] : [NSColor textColor]; + + [theCell setHighlightColor: userHighlightColor ? userHighlightColor : [NSColor colorWithRed:1 green:1 blue:1 alpha:.15]]; + [theCell setTextColor: userTextColor ? userTextColor : [NSColor textColor]]; [theCell setShowDetails:NO]; [theCell setState:NSControlStateValueOn]; [theCell setIconSize:QSSize128]; [theCell setImagePosition:NSImageAbove]; + + } + // Add KVO observers for preference changes + [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@"QSLiquidGlassBezelApplyTint" options:NSKeyValueObservingOptionNew context:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@"QSAppearance1A" options:NSKeyValueObservingOptionNew context:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:@"QSAppearance1T" options:NSKeyValueObservingOptionNew context:nil]; + [self contractWindow:nil]; } +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context { + [self updateColors]; +} + +- (void)updateColors { + NSArray *theControls = [NSArray arrayWithObjects:dSelector, aSelector, iSelector, nil]; +BOOL shouldApplyTint = [[NSUserDefaults standardUserDefaults] boolForKey:@"QSLiquidGlassBezelApplyTint"]; +NSColor *userHighlightColor = [[NSUserDefaults standardUserDefaults] colorForKey:@"QSAppearance1A"]; +NSColor *userTextColor = shouldApplyTint ? [[NSUserDefaults standardUserDefaults] colorForKey:@"QSAppearance1T"] : [NSColor textColor]; + for(QSSearchObjectView *theControl in theControls) { + QSObjectCell *theCell = [theControl cell]; + [theCell setHighlightColor: userHighlightColor ? userHighlightColor : [NSColor colorWithRed:1 green:1 blue:1 alpha:.15]]; + [theCell setTextColor: userTextColor ? userTextColor : [NSColor textColor]]; + + @try { + [theCell setValue:@(NO) forKey:@"stylesLoaded"]; + } @catch (NSException *exception) { + // We couldn't update. Ignore for now.p + } + + [theControl setNeedsDisplay:YES]; + } +} + - (NSSize) maxIconSize { return QSSize32; } |