Skip to content

Commit

Permalink
add lighting mode option for terminal and log widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Jan 24, 2025
1 parent ced39ab commit 0ce2493
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Plugin developers:
- add 'homebridge name' setting to settings page
- migrate bootstrap from `v4` to `v5`
- fix plugin config/bridge screens for certain plugins
- add lighting mode option for terminal and log widgets
- only available when the UI is already in light mode

### Other Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ <h5 class="modal-title">{{ 'status.widget.title_manage_widget' | translate }}</h
</select>
</div>
</li>
} @case ('TerminalWidgetComponent') {
@if (this.isLightMode) {
<li class="list-group-item d-flex flex-column flex-md-row align-items-center">
<label class="mb-2 mb-md-0 w-100 w-md-50">{{ 'settings.display.lighting_mode' | translate }}</label>
<div class="text-start text-md-end w-100 w-md-50">
<select class="custom-select" [(ngModel)]="widget.theme">
<option value="dark">{{ 'settings.display.dark' | translate }}</option>
<option value="light">{{ 'settings.display.light' | translate }}</option>
</select>
</div>
</li>
} } @case ('TerminalWidgetComponent') {
<li class="list-group-item d-flex flex-column flex-md-row align-items-center">
<label class="mb-2 mb-md-0 w-100 w-md-50">{{ 'status.widget.font_size' | translate }}</label>
<div class="text-start text-md-end w-100 w-md-50">
Expand All @@ -104,7 +114,17 @@ <h5 class="modal-title">{{ 'status.widget.title_manage_widget' | translate }}</h
</select>
</div>
</li>
} @case ('ClockWidgetComponent') {
@if (this.isLightMode) {
<li class="list-group-item d-flex flex-column flex-md-row align-items-center">
<label class="mb-2 mb-md-0 w-100 w-md-50">{{ 'settings.display.lighting_mode' | translate }}</label>
<div class="text-start text-md-end w-100 w-md-50">
<select class="custom-select" [(ngModel)]="widget.theme">
<option value="dark">{{ 'settings.display.dark' | translate }}</option>
<option value="light">{{ 'settings.display.light' | translate }}</option>
</select>
</div>
</li>
} } @case ('ClockWidgetComponent') {
<li class="list-group-item d-flex flex-column flex-md-row align-items-center">
<label class="mb-2 mb-md-0 w-100 w-md-50">{{ 'status.widget.clock_timeformat' | translate }}</label>
<div class="text-start text-md-end w-100 w-md-50">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from 'rxjs/operators'

import { ApiService } from '@/app/core/api.service'
import { SettingsService } from '@/app/core/settings.service'
import { environment } from '@/environments/environment'

@Component({
Expand All @@ -32,6 +33,7 @@ export class WidgetControlComponent implements OnInit {
$activeModal = inject(NgbActiveModal)
private $api = inject(ApiService)
private $http = inject(HttpClient)
private $settings = inject(SettingsService)
private $translate = inject(TranslateService)

@Input() widget: any
Expand Down Expand Up @@ -72,6 +74,7 @@ export class WidgetControlComponent implements OnInit {
]

public networkInterfaces: string[] = []
public isLightMode: boolean

constructor() {}

Expand All @@ -96,13 +99,17 @@ export class WidgetControlComponent implements OnInit {
public searchCountryCodeFormatter = (result: any) => `${result.name}, ${result.country}`

ngOnInit() {
this.isLightMode = this.$settings.actualLightingMode === 'light'
if (this.widget.component === 'HomebridgeLogsWidgetComponent' || this.widget.component === 'TerminalWidgetComponent') {
if (!this.widget.fontWeight) {
this.widget.fontWeight = '400'
}
if (!this.widget.fontSize) {
this.widget.fontSize = 15
}
if (!this.widget.theme) {
this.widget.theme = 'dark'
}
}
if (this.widget.component === 'NetworkWidgetComponent') {
// Get a list of active network interfaces from the settings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<div #widgetcontainer class="flex-column d-flex align-items-stretch h-100 w-100" style="background-color: #2b2b2b">
<div
#widgetcontainer
class="flex-column d-flex align-items-stretch h-100 w-100"
[ngStyle]="{ 'background-color': theme === 'dark' ? '#2b2b2b' : '' }"
>
<div
#terminaltitle
style="color: #ffffff; background-color: #2b2b2b"
[ngStyle]="{
'color': theme === 'dark' ? '#ffffff' : '',
'background-color': theme === 'dark' ? '#2b2b2b': '',
}"
class="drag-handler p-2"
[ngClass]="{ 'widget-cursor': widget.draggable }"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Subject } from 'rxjs'
import { ITerminalOptions } from 'xterm'

import { LogService } from '@/app/core/log.service'
import { SettingsService } from '@/app/core/settings.service'

@Component({
templateUrl: './homebridge-logs-widget.component.html',
Expand All @@ -17,6 +18,7 @@ import { LogService } from '@/app/core/log.service'
})
export class HomebridgeLogsWidgetComponent implements OnInit, OnDestroy {
private $log = inject(LogService)
private $settings = inject(SettingsService)

readonly widgetContainerElement = viewChild<ElementRef>('widgetcontainer')
readonly titleElement = viewChild<ElementRef>('terminaltitle')
Expand All @@ -30,19 +32,32 @@ export class HomebridgeLogsWidgetComponent implements OnInit, OnDestroy {

private fontSize = 15
private fontWeight: ITerminalOptions['fontWeight'] = '400'
public theme: 'dark' | 'light' = 'dark'

constructor() {}

ngOnInit() {
this.fontSize = this.widget.fontSize || 15
this.fontWeight = this.widget.fontWeight || 400
if (this.$settings.actualLightingMode === 'dark') {
this.widget.theme = 'dark'
}
this.theme = this.widget.theme || 'dark'

setTimeout(() => {
this.$log.startTerminal(this.termTarget(), {
cursorBlink: false,
theme: {
background: '#2b2b2b',
},
theme: this.theme !== 'light'
? {
background: '#2b2b2b',
}
: {
background: '#00000000',
foreground: '#2b2b2b',
cursor: '#d2d2d2',
selection: '#d2d2d2',
},
allowTransparency: this.theme === 'light',
fontSize: this.fontSize,
fontWeight: this.fontWeight,
}, this.resizeEvent)
Expand All @@ -56,11 +71,34 @@ export class HomebridgeLogsWidgetComponent implements OnInit, OnDestroy {

this.configureEvent.subscribe({
next: () => {
if (this.widget.fontSize !== this.fontSize || this.widget.fontWeight !== this.fontWeight) {
let changed = false
if (this.widget.fontSize !== this.fontSize) {
this.fontSize = this.widget.fontSize
this.fontWeight = this.widget.fontWeight
this.$log.term.options.fontSize = this.widget.fontSize
changed = true
}
if (this.widget.fontWeight !== this.fontWeight) {
this.fontWeight = this.widget.fontWeight
this.$log.term.options.fontWeight = this.widget.fontWeight
changed = true
}
if (this.widget.theme !== this.theme) {
this.theme = this.widget.theme
this.$log.term.options.theme = this.theme !== 'light'
? {
background: '#2b2b2b',
}
: {
background: '#00000000',
foreground: '#2b2b2b',
cursor: '#d2d2d2',
selection: '#d2d2d2',
}
this.$log.term.options.allowTransparency = this.theme === 'light'
changed = true
}

if (changed) {
this.resizeEvent.next(undefined)
setTimeout(() => {
this.$log.term.scrollToBottom()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<div #widgetcontainer class="flex-column d-flex align-items-stretch h-100 w-100" style="background-color: #2b2b2b">
<div
#widgetcontainer
class="flex-column d-flex align-items-stretch h-100 w-100"
[ngStyle]="{ 'background-color': theme === 'dark' ? '#2b2b2b' : '' }"
>
<div
#terminaltitle
style="color: #ffffff; background-color: #2b2b2b"
[ngStyle]="{
'color': theme === 'dark' ? '#ffffff' : '',
'background-color': theme === 'dark' ? '#2b2b2b': '',
}"
class="drag-handler p-2"
[ngClass]="{ 'widget-cursor': widget.draggable }"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TranslatePipe } from '@ngx-translate/core'
import { Subject } from 'rxjs'
import { ITerminalOptions } from 'xterm'

import { SettingsService } from '@/app/core/settings.service'
import { TerminalService } from '@/app/core/terminal.service'

@Component({
Expand All @@ -17,6 +18,7 @@ import { TerminalService } from '@/app/core/terminal.service'
})
export class TerminalWidgetComponent implements OnInit, OnDestroy {
private $terminal = inject(TerminalService)
private $settings = inject(SettingsService)

readonly widgetContainerElement = viewChild<ElementRef>('widgetcontainer')
readonly titleElement = viewChild<ElementRef>('terminaltitle')
Expand All @@ -30,19 +32,32 @@ export class TerminalWidgetComponent implements OnInit, OnDestroy {

private fontSize = 15
private fontWeight: ITerminalOptions['fontWeight'] = '400'
public theme: 'dark' | 'light' = 'dark'

constructor() {}

ngOnInit() {
this.fontSize = this.widget.fontSize || 15
this.fontWeight = this.widget.fontWeight || 400
if (this.$settings.actualLightingMode === 'dark') {
this.widget.theme = 'dark'
}
this.theme = this.widget.theme || 'dark'

setTimeout(() => {
this.$terminal.startTerminal(this.termTarget(), {
cursorBlink: false,
theme: {
background: '#2b2b2b',
},
theme: this.theme !== 'light'
? {
background: '#2b2b2b',
}
: {
background: '#00000000',
foreground: '#2b2b2b',
cursor: '#d2d2d2',
selection: '#d2d2d2',
},
allowTransparency: this.theme === 'light',
fontSize: this.fontSize,
fontWeight: this.fontWeight,
}, this.resizeEvent)
Expand All @@ -56,11 +71,34 @@ export class TerminalWidgetComponent implements OnInit, OnDestroy {

this.configureEvent.subscribe({
next: () => {
if (this.widget.fontSize !== this.fontSize || this.widget.fontWeight !== this.fontWeight) {
let changed = false
if (this.widget.fontSize !== this.fontSize) {
this.fontSize = this.widget.fontSize
this.fontWeight = this.widget.fontWeight
this.$terminal.term.options.fontSize = this.widget.fontSize
changed = true
}
if (this.widget.fontWeight !== this.fontWeight) {
this.fontWeight = this.widget.fontWeight
this.$terminal.term.options.fontWeight = this.widget.fontWeight
changed = true
}
if (this.widget.theme !== this.theme) {
this.theme = this.widget.theme
this.$terminal.term.options.theme = this.theme !== 'light'
? {
background: '#2b2b2b',
}
: {
background: '#00000000',
foreground: '#2b2b2b',
cursor: '#d2d2d2',
selection: '#d2d2d2',
}
this.$terminal.term.options.allowTransparency = this.theme === 'light'
changed = true
}

if (changed) {
this.resizeEvent.next(undefined)
setTimeout(() => {
this.$terminal.term.scrollToBottom()
Expand Down

0 comments on commit 0ce2493

Please sign in to comment.