Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 87237a5

Browse files
committed
Fixed NG01002 in settings.component.ts.
1 parent 604f543 commit 87237a5

File tree

6 files changed

+36
-32
lines changed

6 files changed

+36
-32
lines changed

src/app/api/setting/setting.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class SettingService {
2323
// requestMany and key check because non-ms requests don't have tags yet
2424
return this.websocketService.requestMany({action: 'setting', key: key}).pipe(
2525
first(setting => setting.key === key && typeof setting.value === 'string'),
26-
map(setting => setting.value)
26+
map(setting => setting.value),
2727
);
2828
}
2929

src/app/desktop/desktop.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class DesktopComponent implements OnInit {
5050
ngOnInit(): void {
5151
this.linkages = this.programService.loadCached();
5252
this.programService.loadFresh().then(programs => this.linkages = programs);
53-
this.settings.backgroundImage.getFresh().then();
53+
this.settings.backgroundImage.getFresh().subscribe();
5454
}
5555

5656
onDesktop(): Program[] {

src/app/desktop/windows/settings/settings-entry.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {SettingService} from '../../../api/setting/setting.service';
2+
import {Observable, of} from "rxjs";
3+
import {catchError, map} from "rxjs/operators";
24

35
export abstract class SettingsEntry<T> {
46
protected cached: T;
@@ -18,28 +20,28 @@ export abstract class SettingsEntry<T> {
1820
}
1921
}
2022

21-
async get(): Promise<T> {
23+
get(): Observable<T> {
2224
if (this.cached == null) {
2325
return this.getFresh();
2426
} else {
25-
return this.cached;
27+
return of(this.cached);
2628
}
2729
}
2830

29-
async getFresh(): Promise<T> {
30-
this.settingService.get(this.key).subscribe({
31-
next: (data: string) => {
32-
this.cached = this.deserialize(data);
33-
},
34-
error: (e: Error) => {
31+
getFresh(): Observable<T> {
32+
return this.settingService.get(this.key).pipe(
33+
map((data: string) => {
34+
return this.cached = this.deserialize(data);
35+
}),
36+
catchError((e) => {
3537
// @ts-ignore
3638
if (e.message !== 'unknown setting') {
3739
console.warn(e);
3840
}
3941
this.cached = this.defaultValue;
40-
}
41-
})
42-
return this.cached;
42+
return of(this.cached);
43+
})
44+
);
4345
}
4446

4547
set(value: T) {

src/app/desktop/windows/settings/settings.component.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {WindowComponent, WindowConstraints, WindowDelegate} from '../../window/w
33
import {SettingsService} from './settings.service';
44
import {FormBuilder, FormGroup} from '@angular/forms';
55
import {SettingsEntry} from './settings-entry';
6+
import {forkJoin} from "rxjs";
7+
import {map} from "rxjs/operators";
68

79
@Component({
810
selector: 'app-settings',
@@ -37,11 +39,15 @@ export class SettingsComponent extends WindowComponent implements OnInit {
3739
}
3840

3941
async loadForm() {
40-
const value: { [name: string]: unknown } = {};
41-
for (const [name, setting] of this.settingEntries) {
42-
value[name] = await setting.getFresh();
43-
}
44-
this.form.setValue(value);
42+
forkJoin(this.settingEntries.map(
43+
([name, setting]) => setting.getFresh().pipe(
44+
map(value => ({name, value: value ?? setting.defaultValue}))
45+
)
46+
)).subscribe(values => {
47+
const result: { [name: string]: unknown } = {};
48+
values.forEach(x => result[x.name] = x.value)
49+
this.form.setValue(result);
50+
})
4551
}
4652

4753
async resetSettings() {
@@ -52,6 +58,8 @@ export class SettingsComponent extends WindowComponent implements OnInit {
5258
}
5359

5460
async saveSettings() {
61+
console.log(this.form.value)
62+
console.log(this.settingEntries)
5563
await Promise.all(
5664
this.settingEntries.map(([name, setting]) => setting.set(this.form.value[name]))
5765
);

src/app/desktop/windows/terminal/terminal-states.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {SecurityContext} from '@angular/core';
66
import {SettingsService} from '../settings/settings.service';
77
import {FileService} from '../../../api/files/file.service';
88
import {Path} from '../../../api/files/path';
9-
import {EMPTY, of} from 'rxjs';
9+
import {EMPTY, forkJoin, of} from 'rxjs';
1010
import {Device} from '../../../api/devices/device';
1111
import {WindowDelegate} from '../../window/window-delegate';
1212
import {File} from '../../../api/files/file';
@@ -208,7 +208,7 @@ export class DefaultTerminalState extends CommandTerminalState {
208208
private domSanitizer: DomSanitizer, protected windowDelegate: WindowDelegate, protected activeDevice: Device,
209209
protected terminal: TerminalAPI, public promptColor: string | null = null) {
210210
super();
211-
this.settings.terminalPromptColor.getFresh().then(() => this.refreshPrompt());
211+
this.settings.terminalPromptColor.getFresh().subscribe(() => this.refreshPrompt());
212212
}
213213

214214
static registerPromptAppenders(element: HTMLElement) {
@@ -461,16 +461,16 @@ export class DefaultTerminalState extends CommandTerminalState {
461461
files.filter((file) => {
462462
return file.is_directory;
463463
}).sort().forEach(folder => {
464-
Promise.all([this.settings.terminalLsFolderColor.get(), this.settings.terminalLsPrefix.get()])
465-
.then(([folderColor, lsPrefix]) => {
464+
forkJoin([this.settings.terminalLsFolderColor.get(), this.settings.terminalLsPrefix.get()])
465+
.subscribe(([folderColor, lsPrefix]) => {
466466
this.terminal.output(`<span style="color: ${folderColor};">${lsPrefix ? '[Folder] ' : ''}${folder.filename}</span>`);
467467
});
468468
});
469469

470470
files.filter((file) => {
471471
return !file.is_directory;
472472
}).sort().forEach(file => {
473-
this.settings.terminalLsPrefix.get().then(lsPrefix =>
473+
this.settings.terminalLsPrefix.get().subscribe(lsPrefix =>
474474
this.terminal.outputText(`${(lsPrefix ? '[File] ' : '')}${file.filename}`)
475475
);
476476
});

src/app/websocket.service.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Injectable} from '@angular/core';
22
import {webSocket, WebSocketSubject} from 'rxjs/webSocket';
3-
import {catchError, filter, first, map, mergeMap, switchMap, tap} from 'rxjs/operators';
3+
import {catchError, first, map, mergeMap, switchMap, tap} from 'rxjs/operators';
44
import {firstValueFrom, interval, Observable, of, Subject, throwError} from 'rxjs';
55
import {environment} from '../environments/environment';
66
import {v4 as randomUUID} from 'uuid';
@@ -111,14 +111,8 @@ export class WebsocketService {
111111
requestMany(data: any): Observable<any> {
112112
return interval(50)
113113
.pipe(
114-
filter(() => Boolean(this.socketSubject)),
115-
tap(() => {
116-
if (this.socketSubject) {
117-
this.socketSubject.next(data);
118-
} else {
119-
this.queue.push(data);
120-
}
121-
}),
114+
first(() => Boolean(this.socketSubject)),
115+
tap(() => this.socketSubject.next(data)),
122116
switchMap(() => this.socketSubject),
123117
map(checkResponseError),
124118
);

0 commit comments

Comments
 (0)