Skip to content

Commit

Permalink
feat(core): Allow users to override the loader timeout
Browse files Browse the repository at this point in the history
Fixes #177
  • Loading branch information
oliversalzburg committed Mar 17, 2023
1 parent bd0ee80 commit 94e347e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/documentation/docs/sections/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Allows you to select a language different from the language used in KG.

Initially, KS will just use the language KG is set at, but you can override this language here.

## Other internals

Some users may experience slow loads of KG itself, causing KS to fail to load in time, as the timeout for the loader is "only" 2 minutes.

In case you are impacted by this, set `localStorage["ks.timeout"]` to the amount of milliseconds KS should wait for KG to load. The default value is `120000`, which correlates to the amount of milliseconds in 2 minutes.

<!-- prettier-ignore-start -->
*[JS]: JavaScript
*[KG]: Kittens Game
Expand Down
12 changes: 11 additions & 1 deletion packages/userscript/source/UserScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ export const ksVersion = (prefix = "") => {
return `${prefix}${KS_VERSION}`;
};

// How long to wait for KG to load, in milliseconds.
const TIMEOUT_DEFAULT = 2 * 60 * 1000;

// Allows the user to define a timeout override in their browser's web storage.
// This allows users to extend the timeout period, in case their local configuration
// requires it.
const TIMEOUT_OVERRIDE = !isNil(localStorage["ks.timeout"])
? Number(localStorage["ks.timeout"])
: undefined;

export class UserScript {
readonly gamePage: GamePage;

Expand Down Expand Up @@ -254,7 +264,7 @@ export class UserScript {
return state[0];
}

static async waitForGame(timeout = 30000): Promise<GamePage> {
static async waitForGame(timeout = TIMEOUT_OVERRIDE ?? TIMEOUT_DEFAULT): Promise<GamePage> {
const signals: Array<Promise<unknown>> = [sleep(2000)];

if (isNil(UserScript._gameStartSignal) && typeof UserScript.window.dojo !== "undefined") {
Expand Down

0 comments on commit 94e347e

Please sign in to comment.