Skip to content

Commit

Permalink
Nomenclature changes to make this compatible with web-greeter
Browse files Browse the repository at this point in the history
NodyBroadcastEvent renamed to GreeterBroadcastEvent
Nody class renamed to Comm
window.nody_greeter object renamed to window.greeter_comm
  • Loading branch information
JezerM committed Jun 9, 2022
1 parent 528fb04 commit fc86491
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions themes/dracula/ts/backgrounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Backgrounds {
* Background change requests are handled via broadcast events so that all
* windows correctly update.
*/
window.addEventListener("NodyBroadcastEvent", (ev) => {
window.addEventListener("GreeterBroadcastEvent", (ev) => {
const data: BackgroundData = ev.data as BackgroundData;
if (data.type == "change-background") {
this._backgroundPath = data.path;
Expand Down Expand Up @@ -74,8 +74,8 @@ export class Backgrounds {
for (const path of this._backgroundImages) {
const button = this.createImageButton(path);
button.addEventListener("click", () => {
if (window.nody_greeter) {
window.nody_greeter.broadcast({
if (window.greeter_comm) {
window.greeter_comm.broadcast({
type: "change-background",
path,
});
Expand Down
24 changes: 12 additions & 12 deletions ts/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ export interface WindowMetadata {
* An event that is fired and dispatched when one browser window of a theme
* sends a broadcast to all windows (which happens for multi-monitor setups)
*/
export class NodyBroadcastEvent extends Event {
export class GreeterBroadcastEvent extends Event {
public constructor(
/** Metadata for the window that originated the request */
public readonly window: WindowMetadata,
/** Data sent in the broadcast */
public readonly data: unknown
) {
super("NodyBroadcastEvent");
super("GreeterBroadcastEvent");
}
}

/**
* A class that exposes functionality that is unique to `nody-greeter` and not
* present in `web-greeter`
*/
export class Nody {
export class Comm {
private _window_metadata: WindowMetadata | null = null;
/**
* callback that should be called when the metadata is received
Expand All @@ -64,7 +64,7 @@ export class Nody {
private readonly _ready_promise: Promise<void>;

public constructor() {
window.nody_greeter = this;
window.greeter_comm = this;

ipcRenderer.on(CONSTS.channel.window_metadata, (_ev, metadata) => {
this._window_metadata = metadata;
Expand All @@ -75,13 +75,13 @@ export class Nody {
ipcRenderer.send(CONSTS.channel.window_metadata);

ipcRenderer.on(CONSTS.channel.window_broadcast, (_ev, metadata, data) => {
const event = new NodyBroadcastEvent(metadata, data);
const event = new GreeterBroadcastEvent(metadata, data);
window.dispatchEvent(event);
});

this._ready_promise = new Promise((resolve) => (this._ready = resolve));

return window.nody_greeter;
return window.greeter_comm;
}

public get window_metadata(): WindowMetadata {
Expand Down Expand Up @@ -936,7 +936,7 @@ export class ThemeUtils {
}
}

new Nody();
new Comm();
new ThemeUtils();
new GreeterConfig();
new Greeter();
Expand All @@ -955,29 +955,29 @@ const domLoaded = new Promise<void>((resolve) => {
* Promise that fires when all initialization has completed,
* and the theme can start (i.e. _ready_event can be sent)
*/
const readyPromise = Promise.all([domLoaded, window.nody_greeter?.whenReady()]);
const readyPromise = Promise.all([domLoaded, window.greeter_comm?.whenReady()]);

readyPromise.then(() => {
if (window._ready_event) window.dispatchEvent(window._ready_event);
});

export declare const nody_greeter: Nody;
export declare const greeter_comm: Comm;
export declare const lightdm: Greeter;
export declare const greeter_config: GreeterConfig;
export declare const theme_utils: ThemeUtils;
export declare const _ready_event: Event;

declare global {
interface Window {
nody_greeter: Nody | undefined;
greeter_comm: Comm | undefined;
lightdm: Greeter | undefined;
greeter_config: GreeterConfig | undefined;
theme_utils: ThemeUtils | undefined;
_ready_event: Event | undefined;

addEventListener(
type: "NodyBroadcastEvent",
listener: (ev: NodyBroadcastEvent) => void,
type: "GreeterBroadcastEvent",
listener: (ev: GreeterBroadcastEvent) => void,
options?: boolean | AddEventListenerOptions | undefined
): void;

Expand Down

0 comments on commit fc86491

Please sign in to comment.