added config file editor

This commit is contained in:
Eugene Pankov
2018-08-26 22:27:50 +02:00
parent a98f2ce12d
commit 2e558e2aa2
12 changed files with 420 additions and 9 deletions

View File

@@ -19,8 +19,6 @@ ngb-tabset.vertical(type='pills', [activeId]='activeTab')
i.fa.fa-bug
span Report a problem
.form-line
.header
.title Theme
@@ -213,6 +211,15 @@ ngb-tabset.vertical(type='pills', [activeId]='activeTab')
i.fa.fa-bug
span Open DevTools
.form-line
.header
.title Enable analytics
.description We use Google Analytics
toggle(
[(ngModel)]='config.store.enableAnalytics',
(ngModelChange)='config.save(); config.requestRestart()',
)
.form-line
.header
.title Custom CSS
@@ -253,3 +260,29 @@ ngb-tabset.vertical(type='pills', [activeId]='activeTab')
| {{provider.title}}
ng-template(ngbTabContent)
settings-tab-body([provider]='provider')
ngb-tab(id='config-file')
ng-template(ngbTabTitle)
| Config file
ng-template.test(ngbTabContent)
.d-flex.flex-column.w-100.h-100
.h-100.d-flex
.w-100.d-flex.flex-column
h3 Config file
textarea.form-control.h-100(
[(ngModel)]='configFile'
)
.w-100.d-flex.flex-column
h3 Defaults
textarea.form-control.h-100(
[(ngModel)]='configDefaults',
readonly
)
.mt-3
button.btn.btn-primary((click)='saveConfigFile()', *ngIf='isConfigFileValid()')
i.fa.fa-check.mr-2
| Save and apply
button.btn.btn-primary(disabled, *ngIf='!isConfigFileValid()')
i.fa.fa-warning.mr-2
| Invalid syntax

View File

@@ -20,5 +20,5 @@
textarea {
font-family: 'Source Sans Mono', monospace;
height: 120px;
min-height: 120px;
}

View File

@@ -1,3 +1,5 @@
import * as yaml from 'js-yaml'
import { Subscription } from 'rxjs'
import { Component, Inject, Input } from '@angular/core'
import { ElectronService, DockingService, ConfigService, IHotkeyDescription, HotkeyProvider, BaseTabComponent, Theme, HostAppService, Platform, HomeBaseService } from 'terminus-core'
@@ -17,6 +19,9 @@ export class SettingsTabComponent extends BaseTabComponent {
hotkeyDescriptions: IHotkeyDescription[]
screens: any[]
Platform = Platform
configDefaults: any
configFile: string
private configSubscription: Subscription
constructor (
public config: ConfigService,
@@ -34,6 +39,12 @@ export class SettingsTabComponent extends BaseTabComponent {
this.screens = this.docking.getScreens()
this.settingsProviders = config.enabledServices(this.settingsProviders)
this.themes = config.enabledServices(this.themes)
this.configDefaults = yaml.safeDump(config.getDefaults())
this.configFile = config.readRaw()
this.configSubscription = config.changed$.subscribe(() => {
this.configFile = config.readRaw()
})
}
getRecoveryToken (): any {
@@ -41,6 +52,7 @@ export class SettingsTabComponent extends BaseTabComponent {
}
ngOnDestroy () {
this.configSubscription.unsubscribe()
this.config.save()
}
@@ -48,4 +60,19 @@ export class SettingsTabComponent extends BaseTabComponent {
this.electron.app.relaunch()
this.electron.app.exit()
}
saveConfigFile () {
if (this.isConfigFileValid()) {
this.config.writeRaw(this.configFile)
}
}
isConfigFileValid () {
try {
yaml.safeLoad(this.configFile)
return true
} catch (_) {
return false
}
}
}

View File

@@ -12,6 +12,12 @@
:host /deep/ ngb-tabset > .tab-content {
padding: 15px 30px;
margin: 0;
flex: auto;
overflow-y: auto;
flex: auto;
display: flex;
position: relative;
}
:host /deep/ ngb-tabset > .tab-content > .tab-pane {
width: 100%;
}

View File

@@ -5,6 +5,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { NgPipesModule } from 'ngx-pipes'
import { ToolbarButtonProvider, TabRecoveryProvider } from 'terminus-core'
import TerminusCorePlugin from 'terminus-core'
import { HotkeyInputModalComponent } from './components/hotkeyInputModal.component'
import { MultiHotkeyInputComponent } from './components/multiHotkeyInput.component'
@@ -20,6 +21,7 @@ import { RecoveryProvider } from './recoveryProvider'
FormsModule,
NgbModule,
NgPipesModule,
TerminusCorePlugin,
],
providers: [
{ provide: ToolbarButtonProvider, useClass: ButtonProvider, multi: true },