Skip to content

Commit

Permalink
add server ping in debug settings, add version check
Browse files Browse the repository at this point in the history
  • Loading branch information
Lurkars committed May 31, 2024
1 parent d88012e commit 2a76f85
Show file tree
Hide file tree
Showing 18 changed files with 313 additions and 86 deletions.
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gloomhavensecretariat",
"version": "0.97.1",
"version": "0.98.0",
"license": "AGPL3",
"description": "Gloomhaven Secretariat is a Gloomhaven/Frosthaven Companion app.",
"homepage": "https://gloomhaven-secretariat.de",
Expand Down Expand Up @@ -76,7 +76,7 @@
"private": true,
"dependencies": {
"@angular/animations": "^18.0.1",
"@angular/cdk": "^18.0.0",
"@angular/cdk": "^18.0.1",
"@angular/common": "^18.0.1",
"@angular/compiler": "^18.0.1",
"@angular/core": "^18.0.1",
Expand Down Expand Up @@ -104,7 +104,7 @@
"@types/jasmine": "~5.1.4",
"@types/leaflet": "^1.9.12",
"@types/uuid": "^9.0.8",
"electron": "^30.0.8",
"electron": "^30.0.9",
"electron-builder": "^24.13.3",
"http-server": "^14.1.1",
"husky": "^9.0.11",
Expand Down
3 changes: 2 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ import { ElementComponent } from './ui/header/element/element';
import { ElementIconComponent } from './ui/header/element/element-icon';
import { GameClockDialogComponent } from './ui/header/game-clock/game-clock';
import { HeaderComponent } from './ui/header/header';
import { AboutMenuComponent } from './ui/header/menu/about/about';
import { CampaignMenuComponent } from './ui/header/menu/campaign/campaign';
import { CharacterMenuComponent } from './ui/header/menu/character/character';
import { DatamanagementMenuComponent } from './ui/header/menu/datamanagement/datamanagement';
Expand Down Expand Up @@ -168,7 +169,7 @@ export class GhsErrorHandler extends ErrorHandler {
MainComponent,
HeaderComponent, ElementIconComponent, ElementComponent,
PartySheetComponent, PartySheetDialogComponent, PartyWeekDialogComponent, PartyBuildingsComponent, WorldMapComponent, ScenarioConclusionComponent, BuildingUpgradeDialog, ScenarioRequirementsComponent, ScenarioRequirementsDialogComponent, TreasuresDialogComponent, PartyResourcesDialogComponent,
MainMenuComponent, CharacterMenuComponent, MonsterMenuComponent, SettingsMenuComponent, SettingMenuComponent, SettingMenuTitleComponent, DatamanagementMenuComponent, ScenarioMenuComponent, ScenarioChartDialogComponent, ScenarioChartPopupDialog, SectionMenuComponent, ServerMenuComponent, SettingsDebugMenuComponent, UndoDialogComponent, CampaignMenuComponent,
MainMenuComponent, CharacterMenuComponent, MonsterMenuComponent, SettingsMenuComponent, SettingMenuComponent, SettingMenuTitleComponent, DatamanagementMenuComponent, ScenarioMenuComponent, ScenarioChartDialogComponent, ScenarioChartPopupDialog, SectionMenuComponent, ServerMenuComponent, SettingsDebugMenuComponent, UndoDialogComponent, AboutMenuComponent, CampaignMenuComponent,
FooterComponent,
LootComponent, LootDeckComponent, LootRandomItemDialogComponent, LootDeckFullscreenComponent, LootDeckDialogComponent, LootDeckStandaloneComponent, LootApplyDialogComponent,
HintDialogComponent, ScenarioRulesComponent,
Expand Down
26 changes: 26 additions & 0 deletions src/app/game/businesslogic/StateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,15 @@ export class StateManager {
gameManager.stateManager.updatePermissions();
gameManager.stateManager.serverError = "";
break;
case "ping":
console.debug("Received ping answer...");
break;
case "error":
// migration
if (message.message == "No enum constant de.champonthis.ghs.server.socket.model.MessageType.PING") {
console.debug("Received ping answer...");
break;
}
console.warn("[GHS] Error: ", message);
if (message.message.startsWith("Permission(s) missing") || message.message.startsWith("invalid revision")) {
if (gameManager.stateManager.lastAction == "redo" || gameManager.stateManager.lastAction == "update") {
Expand All @@ -357,6 +365,8 @@ export class StateManager {
window.document.body.classList.remove('working');
window.document.body.classList.remove('server-sync');
break;
default:
gameManager.uiChange.emit();
}
} catch (e) {
gameManager.stateManager.errorLog.push(ev.data);
Expand Down Expand Up @@ -395,6 +405,7 @@ export class StateManager {
}

gameManager.stateManager.updatePermissions();
gameManager.uiChange.emit();
}
}

Expand Down Expand Up @@ -438,6 +449,21 @@ export class StateManager {
}
}

sendPing() {
if (settingsManager.settings.serverUrl && settingsManager.settings.serverPort && settingsManager.settings.serverCode) {
if (this.ws && this.ws.readyState == WebSocket.OPEN) {
let message = {
"code": settingsManager.settings.serverCode,
"type": "ping"
}
if (settingsManager.settings.logServerMessages) console.debug('WS sending ping');
this.ws.send(JSON.stringify(message));
} else {
this.connect();
}
}
}

wsState(): number {
if (settingsManager.settings.serverUrl && settingsManager.settings.serverPort && settingsManager.settings.serverCode) {
return this.ws && this.ws.readyState || -1;
Expand Down
3 changes: 2 additions & 1 deletion src/app/game/model/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class Settings {
serverAutoconnect: boolean = true;
serverCode: string | undefined;
serverPassword: string | undefined;
serverPing: number = 0;
serverPort: number | undefined;
serverSettings: boolean = false;
serverUrl: string | undefined;
Expand Down Expand Up @@ -168,5 +169,5 @@ export class Settings {
}

export const localSettings: string[] = [
"animations", "artwork", "automaticAttackModifierFullscreen", "autoBackup", "autoBackupFinish", "autoBackupUrl", "automaticGameClock", "automaticTheme", "autoscroll", "barsize", "backupHint", "browserNavigation", "buildingEffectsVisible", "buildingInteractionsVisible", "calendarLocked", "characterAttackModifierAnimate", "characterAttackModifierDeckPermanent", "characterAttackModifierDeckPermanentActive", "characterItemsPermanent", "characterItemsPermanentActive", "characterItemsPermanentEquipped", "characterItemsPermanentSorted", "characterItemsPermanentZoom", "characterCompact", "characterSheetCompact", "characterSheetLocked", "columns", "columnsForce", "debugEditWorldMap", "debugRightClick", "disableAnimations", "disableArtwork", "disableColumns", "disableDragFigures", "disablePinchZoom", "disableWakeLock", "dragFigures", "dragValues", "errata", "fhStyle", "fontsize", "gameClock", "globalFontsize", "globalMapHighlighting", "fullscreen", "hideCharacterHP", "hideCharacterLoot", "hideCharacterXP", "hints", "logServerMessages", "pinchZoom", "portraitMode", "pressDoubleClick", "serverAutoconnect", "serverCode", "serverPassword", "serverPort", "serverSettings", "serverUrl", "serverWss", "showAllSections", "showBossMonster", "showHiddenMonster", "showOnlyUnfinishedScenarios", "statAnimations", "theme", "tooltips", "wakeLock", "zoom"
"animations", "artwork", "automaticAttackModifierFullscreen", "autoBackup", "autoBackupFinish", "autoBackupUrl", "automaticGameClock", "automaticTheme", "autoscroll", "barsize", "backupHint", "browserNavigation", "buildingEffectsVisible", "buildingInteractionsVisible", "calendarLocked", "characterAttackModifierAnimate", "characterAttackModifierDeckPermanent", "characterAttackModifierDeckPermanentActive", "characterItemsPermanent", "characterItemsPermanentActive", "characterItemsPermanentEquipped", "characterItemsPermanentSorted", "characterItemsPermanentZoom", "characterCompact", "characterSheetCompact", "characterSheetLocked", "columns", "columnsForce", "debugEditWorldMap", "debugRightClick", "disableAnimations", "disableArtwork", "disableColumns", "disableDragFigures", "disablePinchZoom", "disableWakeLock", "dragFigures", "dragValues", "errata", "fhStyle", "fontsize", "gameClock", "globalFontsize", "globalMapHighlighting", "fullscreen", "hideCharacterHP", "hideCharacterLoot", "hideCharacterXP", "hints", "logServerMessages", "pinchZoom", "portraitMode", "pressDoubleClick", "serverAutoconnect", "serverCode", "serverPassword", "serverPing", "serverPort", "serverSettings", "serverUrl", "serverWss", "showAllSections", "showBossMonster", "showHiddenMonster", "showOnlyUnfinishedScenarios", "statAnimations", "theme", "tooltips", "wakeLock", "zoom"
];
47 changes: 47 additions & 0 deletions src/app/ui/header/menu/about/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<div class="menu-container about">
<div class="line">
<p [ghs-label]="'about.ip'"
[ghs-label-args]="['<a href=\'https:\/\/cephalofair.com\' target=\'_blank\'>Cephalofair Games</a>']">
</p>
</div>
<div class="line version">
<a target="_blank"
[href]="'https://github.com/Lurkars/gloomhavensecretariat/releases/tag/v' + version">Gloomhaven
Secretariat
v{{version}}</a>

<div class="version-info">
<span class="unknown" *ngIf="!updateVersion">
<span [ghs-label]="'about.version.unknown'"></span>
</span>
<span class="latest" *ngIf="updateVersion && updateVersion.latest">
<span [ghs-label]="'about.version.latest'"></span>
</span>
<span class="update" *ngIf="updateVersion && !updateVersion.latest">
<span [ghs-label]="'about.version.update'"
[ghs-label-args]="[updateVersion.version, updateVersion.url]"></span>
</span>
<a class="force" *ngIf="!updateVersion || !updateVersion.latest" (click)="forceUpdate()"><span
[ghs-label]="'about.forceUpdate'"></span></a>
</div>
</div>

<div class="line">
<div class="columns">
<div class="column">
<p>
<a href="https://ko-fi.com/lurkars" target="_blank"><span [ghs-label]="'about.support'"></span></a>
</p>
</div>
<div class="column">
<p><a href="https://github.com/Lurkars/gloomhavensecretariat" target="_blank"><span
[ghs-label]="'about.sourceCode'"></span></a></p>
</div>
<div class="column">
<p [ghs-label]="'about.license'"
[ghs-label-args]="['<a href=\'https:\/\/\github.com\/Lurkars\/gloomhavensecretariat\/blob\/main\/LICENSE\' target=\'_blank\'> AGPL3</a>']">
</p>
</div>
</div>
</div>
</div>
30 changes: 30 additions & 0 deletions src/app/ui/header/menu/about/about.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.version-info {
display: flex;
justify-content: center;
align-items: center;
font-family: var(--ghs-font-title);
font-size: calc(var(--ghs-unit) * 2.5 * var(--ghs-dialog-factor));
color: var(--ghs-color-gray);
margin-left: calc(var(--ghs-unit) * 1.5 * var(--ghs-dialog-factor));

span {
margin-right: calc(var(--ghs-unit) * 1 * var(--ghs-dialog-factor));

&.unknown {
font-size: calc(var(--ghs-unit) * 2 * var(--ghs-dialog-factor));
color: var(--ghs-color-darkgray);
}

&.latest {
color: var(--ghs-color-darkgreen);
}

&.update {
color: var(--ghs-color-yellow);
}
}

.force {
margin-left: calc(var(--ghs-unit) * 1.5 * var(--ghs-dialog-factor));
}
}
48 changes: 48 additions & 0 deletions src/app/ui/header/menu/about/about.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Component, EventEmitter, OnInit, Output } from "@angular/core";
import { SwUpdate } from "@angular/service-worker";
import packageJson from '../../../../../../package.json';


@Component({
selector: 'ghs-about-menu',
templateUrl: 'about.html',
styleUrls: ['../menu.scss', 'about.scss']
})
export class AboutMenuComponent implements OnInit {

@Output() close = new EventEmitter();
version = packageJson.version;
updateVersion: { latest: boolean, version: string, url: string } | undefined;

constructor(private swUpdate: SwUpdate) { }

async ngOnInit() {
await fetch('https://api.github.com/repos/lurkars/gloomhavensecretariat/releases/latest')
.then(response => {
if (!response.ok) {
throw Error();
}
return response.json();
}).then((value: any) => {
this.updateVersion = { latest: value.tag_name == this.version || value.tag_name == 'v' + this.version, version: value.tag_name, url: value.html_url };
});
}

forceUpdate(): void {
if (this.swUpdate.isEnabled) {
this.swUpdate.activateUpdate().then(() => {
this.clearAndRefresh();
});
} else {
this.clearAndRefresh();
}
}

async clearAndRefresh() {
if ('caches' in window) {
const keyList = await caches.keys();
await Promise.all(keyList.map(async (key) => await caches.delete(key)));
}
window.location.reload()
}
}
6 changes: 6 additions & 0 deletions src/app/ui/header/menu/debug/debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@
<a tabclick (click)="settingsManager.validateEditionData()"><span
[ghs-label]="'tools.validateEditionData'"></span></a>
</div>
<div class="separator"></div>
<div class="line">
<label>
<input tabclick type="checkbox" [checked]="settingsManager.settings.logServerMessages"
(change)="settingsManager.toggle('logServerMessages')">
<span [ghs-label]="'settings.debug.logServerMessages'"></span>
</label>
</div>
<div class="line ping">
<label class="label"><span [ghs-label]="'server.ping'"></span></label>
<input type="number" #serverPing [value]="settingsManager.settings.serverPing || '0'" (keyup)="0"
(change)="setServerPing($event)" [ghs-label]="'server.ping'" [ghs-label-attribute]="'placeholder'">
</div>
<div class="separator"></div>
<div class="line">
<a tabclick [routerLink]="'/'"><span [ghs-label]="'tools.backToGhs'"></span></a>
Expand Down
5 changes: 5 additions & 0 deletions src/app/ui/header/menu/debug/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ import { settingsManager, SettingsManager } from "src/app/game/businesslogic/Set
})
export class SettingsDebugMenuComponent {
settingsManager: SettingsManager = settingsManager;

setServerPing(event: any) {
settingsManager.settings.serverPing = event.target.value;
settingsManager.storeSettings();
}
}
Loading

0 comments on commit 2a76f85

Please sign in to comment.