Skip to content

Commit

Permalink
DI Window
Browse files Browse the repository at this point in the history
  • Loading branch information
Akamig committed Oct 15, 2024
1 parent 2a9df04 commit 176106b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/main/src/modules/Game/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {BrowserWindow} from 'electron/main';

export default class Game {
private _gameNode: ChildProcessWithoutNullStreams | null = null;
private _window: BrowserWindow;
private _window: () => BrowserWindow;

constructor(window: BrowserWindow) {
this._window = window;
constructor(getWindow: () => BrowserWindow) {
this._window = getWindow;
this.registerEvents();
}

Expand All @@ -35,7 +35,7 @@ export default class Game {

private startGame = (): void => {
if (this.isStartable()!) {
this._window.webContents.send('game-state', false);
this._window().webContents.send('game-state', false);
return;
}

Expand All @@ -44,17 +44,17 @@ export default class Game {
this._gameNode.on('error', err => console.log(err));
this._gameNode.on('close', () => {
this._gameNode = null;
this._window.webContents.send('game-state', false);
this._window().webContents.send('game-state', false);
});

if (this._gameNode !== null) {
this._window.webContents.send('game-state', true);
this._window().webContents.send('game-state', true);
}
};

private endGame = (): void => {
if (this._gameNode === null) {
this._window.webContents.send('game-state', false);
this._window().webContents.send('game-state', false);
console.error('game already closed');
return;
}
Expand Down
10 changes: 10 additions & 0 deletions packages/main/src/modules/UI/Window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ export default class Window {
this.window.focus();
}

public getWindow() {
//const window = BrowserWindow.getAllWindows().find(w => !w.isDestroyed())

if (window === undefined) {
this.createWindow().then(() => this.getWindow());
}

return this.window;
}

/**
* If the 'show' property of the BrowserWindow's constructor is omitted from the initialization options,
* it then defaults to 'true'. This can cause flickering as the window loads the html content,
Expand Down

0 comments on commit 176106b

Please sign in to comment.