Skip to content

Commit ec111a9

Browse files
committed
fix broken derived classes
1 parent 13bcda4 commit ec111a9

4 files changed

Lines changed: 73 additions & 54 deletions

File tree

scripts/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LightDMMessageType, LightDMPromptType, LightDMUser, lightdm } from 'nody-greeter-types/index';
1+
import { LightDMMessageType, LightDMPromptType, lightdm } from 'nody-greeter-types/index';
22

33
export interface AuthenticatorEvents {
44
/**

scripts/ui/lockscreen.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
import { Authenticator } from "../auth";
22
import { LightDMUser } from "nody-greeter-types";
3-
import { Screen } from "./screen";
3+
import { UIScreen, UILockScreenElements } from "./screen";
44

5-
export interface UILockScreenElements {
6-
lockForm: HTMLFormElement;
7-
displayName: HTMLHeadingElement;
8-
loginName: HTMLHeadingElement;
9-
passwordInput: HTMLInputElement;
10-
unlockButton: HTMLButtonElement;
11-
}
12-
13-
export class LockScreenUI extends Screen {
5+
export class LockScreenUI extends UIScreen {
6+
public readonly _form: UILockScreenElements;
147
private readonly _activeSession: LightDMUser;
158

169
public constructor(auth: Authenticator, activeSession: LightDMUser) {
17-
super();
10+
super(auth, {
11+
authenticationStart: () => {
12+
this._disableForm();
13+
},
14+
authenticationComplete: () => {
15+
// TODO: Add a loading animation here
16+
},
17+
authenticationFailure: () => {
18+
this._enableForm();
19+
this._wigglePasswordInput();
20+
},
21+
errorMessage: (message: string) => {
22+
alert(message);
23+
},
24+
infoMessage: (message: string) => {
25+
alert(message);
26+
},
27+
});
1828

1929
this._activeSession = activeSession;
2030
this._auth = auth;
@@ -26,10 +36,10 @@ export class LockScreenUI extends Screen {
2636
unlockButton: document.getElementById('unlock-button') as HTMLButtonElement,
2737
} as UILockScreenElements;
2838

29-
this._initLockScreenForm();
39+
this._initForm();
3040
}
3141

32-
private _initLockScreenForm(): void {
42+
protected _initForm(): void {
3343
const form = this._form as UILockScreenElements;
3444

3545
// Populate lock screen data

scripts/ui/loginscreen.ts

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
import { Authenticator } from "../auth";
2-
import { Screen } from "./screen";
2+
import { UILoginElements, UIScreen } from "./screen";
33

4-
export interface UILoginElements {
5-
loginForm: HTMLFormElement;
6-
loginInput: HTMLInputElement;
7-
passwordInput: HTMLInputElement;
8-
loginButton: HTMLButtonElement;
9-
}
4+
export class LoginScreenUI extends UIScreen {
5+
public readonly _form: UILoginElements;
106

11-
export class LoginScreenUI extends Screen {
127
public constructor(auth: Authenticator) {
13-
super();
8+
super(auth, {
9+
authenticationStart: () => {
10+
this._disableForm();
11+
},
12+
authenticationComplete: () => {
13+
// TODO: Add a loading animation here
14+
},
15+
authenticationFailure: () => {
16+
this._enableForm();
17+
this._wigglePasswordInput();
18+
},
19+
errorMessage: (message: string) => {
20+
alert(message);
21+
},
22+
infoMessage: (message: string) => {
23+
alert(message);
24+
},
25+
});
1426

1527
this._auth = auth;
1628
this._form = {
@@ -20,10 +32,10 @@ export class LoginScreenUI extends Screen {
2032
loginButton: document.getElementById('login-button') as HTMLButtonElement,
2133
} as UILoginElements;
2234

23-
this._initLoginForm();
35+
this._initForm();
2436
}
2537

26-
private _initLoginForm(): void {
38+
protected _initForm(): void {
2739
const form = this._form as UILoginElements;
2840

2941
// This event gets called when the user clicks the login button or submits the login form in any other way
@@ -83,23 +95,4 @@ export class LoginScreenUI extends Screen {
8395
}
8496
return form.passwordInput;
8597
}
86-
87-
protected _events = {
88-
authenticationStart: () => {
89-
this._disableForm();
90-
},
91-
authenticationComplete: () => {
92-
// TODO: Add a loading animation here
93-
},
94-
authenticationFailure: () => {
95-
this._enableForm();
96-
this._wigglePasswordInput();
97-
},
98-
errorMessage: (message: string) => {
99-
alert(message);
100-
},
101-
infoMessage: (message: string) => {
102-
alert(message);
103-
},
104-
}
10598
}

scripts/ui/screen.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
import { Authenticator, AuthenticatorEvents } from "../auth";
2-
import { UILockScreenElements } from "./lockscreen";
3-
import { UILoginElements } from "./loginscreen";
42

5-
export declare class Screen {
3+
export interface UILoginElements {
4+
loginForm: HTMLFormElement;
5+
loginInput: HTMLInputElement;
6+
passwordInput: HTMLInputElement;
7+
loginButton: HTMLButtonElement;
8+
}
9+
10+
export interface UILockScreenElements {
11+
lockForm: HTMLFormElement;
12+
displayName: HTMLHeadingElement;
13+
loginName: HTMLHeadingElement;
14+
passwordInput: HTMLInputElement;
15+
unlockButton: HTMLButtonElement;
16+
}
17+
18+
export abstract class UIScreen {
619
protected _auth: Authenticator;
7-
protected _form: UILockScreenElements | UILoginElements;
20+
abstract _form: UILockScreenElements | UILoginElements;
821
protected _events: AuthenticatorEvents;
922

10-
public constructor();
23+
public constructor(auth: Authenticator, events: AuthenticatorEvents) {
24+
this._auth = auth;
25+
this._events = events;
26+
};
1127

12-
protected _initForm(): void;
13-
protected _disableForm(): void;
14-
protected _enableForm(): void;
15-
protected _wigglePasswordInput(): void;
16-
protected _getInputToFocusOn(): HTMLInputElement;
28+
protected abstract _initForm(): void;
29+
protected abstract _disableForm(): void;
30+
protected abstract _enableForm(): void;
31+
protected abstract _wigglePasswordInput(): void;
32+
protected abstract _getInputToFocusOn(): HTMLInputElement;
1733
}

0 commit comments

Comments
 (0)