Skip to content

Commit

Permalink
Convert UILoginController to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
dangeredwolf committed May 17, 2022
1 parent abfaabd commit 58a2328
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/UILoginController.js → src/UILoginController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@

import { enableStylesheetExtension, disableStylesheetExtension } from "./StylesheetExtensions";
import { I18n } from "./I18n";
import { UILanguagePicker } from "./UILanguagePicker";
import { openSettings } from "./UISettings";
import { getPref } from "./StoragePreferences";
import { loginPage } from "./DataMustaches";

let ugltStarted = false;
window.loginIntervalTick = 0;
let loginInterval;
let ugltStarted: boolean = false;
let loginIntervalTick: number = 0;
let signinSheetPings: number = 0;

// Updates the "Good morning" / "Good afternoon" / "Good evening"
// text on the login screen every once in a while (10s, ish)

function startUpdateGoodLoginText() {
const startUpdateGoodLoginText = (): void => {

// Don't run if we already started
if (ugltStarted) {
Expand All @@ -33,7 +31,7 @@ function startUpdateGoodLoginText() {
// we can't do this in the new login mustache because when it's initialised,
// MTDURLExchange hasn't completed yet

$(".startflow-background").attr("style",`background-image:url(${mtdBaseURL}assets/img/bg1.webp)`)
$(".startflow-background").attr("style",`background-image:url(${window.mtdBaseURL}assets/img/bg1.webp)`)

if (window?.desktopConfig?.customLoginImage) {
if (window.desktopConfig.customLoginImage.match(/https:\/\//gm) !== null) {
Expand Down Expand Up @@ -65,37 +63,37 @@ function startUpdateGoodLoginText() {
If so, it activates the login page stylesheet extension
*/

export function checkIfSigninFormIsPresent() {
export const checkIfSigninFormIsPresent = (): void => {

if ($(".app-signin-form").length > 0 || $("body>.js-app-loading.login-container:not([style])").length > 0) {
html.addClass("signin-sheet-now-present");
window.html.addClass("signin-sheet-now-present");

window.loginIntervalTick++;
loginIntervalTick++;
enableStylesheetExtension("loginpage");

if (window.loginIntervalTick > 5) {
if (loginIntervalTick > 5) {
clearInterval(window.loginInterval);
}
} else {
if (typeof window.signinSheetPings === "undefined") {
window.signinSheetPings = 0;
if (typeof signinSheetPings === "undefined") {
signinSheetPings = 0;
}

window.signinSheetPings++;
signinSheetPings++;

if (window.signinSheetPings > 6) {
if (signinSheetPings > 6) {
console.log("I am no longer asking");
clearInterval(window.loginInterval);
}
console.log("Not on signin sheet anymore");
disableStylesheetExtension("loginpage");
html.removeClass("signin-sheet-now-present");
window.html.removeClass("signin-sheet-now-present");
}

}
// replaces login page with moderndeck one

export function loginTextReplacer() {
export const loginTextReplacer = (): void => {
if ($(".mtd-signin-form").length <= 0) {
console.info("oh no, we're too late!");

Expand Down

0 comments on commit 58a2328

Please sign in to comment.