Skip to content

Commit

Permalink
Merge pull request #109 from Moros1138/better-preload
Browse files Browse the repository at this point in the history
Better preload
  • Loading branch information
Moros1138 authored Jun 26, 2024
2 parents f74dd8b + 6530856 commit 8bda708
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 55 deletions.
2 changes: 1 addition & 1 deletion resources/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ a:focus {
display: flex !important;
}

.hidden { display: none; }
.hidden { display: none !important; }

.lm_content {
overflow: visible !important;
Expand Down
2 changes: 1 addition & 1 deletion resources/css/app/loading.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pgetinker-loading {
display: none;
display: flex;
position: absolute;
top: 49px;
bottom: 0;
Expand Down
44 changes: 44 additions & 0 deletions resources/js/app-preload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { conformStorage, getStorageValue, setStorageValue, removeStorageKey } from './lib/storage';
import './lib/lucide';

// @ts-ignore
import agreeDialog from './lib/agreeDialog';

conformStorage();

const preloader = () =>
{
import("./app.ts")
.then((object) =>
{
const PGEtinker = object.default;

new PGEtinker();
})
.catch((reason) =>
{
console.log(reason);
});
};

if(!getStorageValue("agreed-to-terms"))
{
agreeDialog()
.then(() =>
{
setStorageValue("agreed-to-terms", true);
preloader();
})
.catch(() =>
{
removeStorageKey("code");
removeStorageKey("theme");
removeStorageKey("layout");
removeStorageKey("version");
window.location.pathname = "/disagree";
});
}
else
{
preloader();
}
82 changes: 37 additions & 45 deletions resources/js/app.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import './lib/bootstrap';
import { conformStorage, getStorageValue, setStorageValue, removeStorageKey } from './lib/storage';
import { getStorageValue, setStorageValue } from './lib/storage';
import './lib/goldenLayout';
import './lib/lucide';

import version from "./lib/version";
// @ts-ignore
import agreeDialog from './lib/agreeDialog';
// @ts-ignore
import mobileMenuDialog from './lib/mobileMenuDialog';
// @ts-ignore
import newsDialog from './lib/newsDialog';
Expand Down Expand Up @@ -34,7 +32,7 @@ import { createToast, ToastType } from './lib/createToast';

declare function GoldenLayout(...args: any[]): void;

class PGEtinker
export default class PGEtinker
{
consolePanel;
editorPanel;
Expand All @@ -51,7 +49,6 @@ class PGEtinker

constructor()
{
conformStorage();

this.consolePanel = new ConsolePanel(this);
this.compilerOutputPanel = new CompilerOutputPanel(this);
Expand Down Expand Up @@ -150,29 +147,9 @@ class PGEtinker
newsDialog();
});

if(!getStorageValue("agreed-to-terms"))
{
agreeDialog()
.then(() =>
{
setStorageValue("agreed-to-terms", true);
this.SetupLayout();
})
.catch(() =>
{
removeStorageKey("code");
removeStorageKey("theme");
removeStorageKey("layout");
removeStorageKey("version");
window.location.pathname = "/disagree";
});
}
else
{
this.SetupLayout();
this.setActiveTab("editor");
this.setActiveTab("problems");
}
this.SetupLayout();
this.setActiveTab("editor");
this.setActiveTab("problems");
}

setActiveTab(id: string)
Expand Down Expand Up @@ -397,7 +374,7 @@ class PGEtinker

async SetupLayout()
{
document.querySelector("#pgetinker-loading")!.classList.toggle("display-flex", true);
document.querySelector("#pgetinker-loading")!.classList.toggle("hidden", false);

await this.editorPanel.onPreInit();

Expand All @@ -417,7 +394,6 @@ class PGEtinker
setStorageValue("layout", this.layout.toConfig());
}
});

this.layout.on("initialised", async() =>
{
this.layoutInitialized = true;
Expand All @@ -436,7 +412,6 @@ class PGEtinker

setTimeout(() =>
{
document.querySelector("#pgetinker-loading")!.classList.toggle("display-flex", false);
this.setActiveTab("editor");
}, 500)
});
Expand All @@ -462,23 +437,40 @@ class PGEtinker
// update editor theme
await this.editorPanel.updateConfiguration();

setTimeout(() =>
//
const isVsCodeTheme = () =>
{
document.body.classList.toggle("dark", !light);
document.body.classList.toggle("light", light);

// update golden layout theme
let goldenLayoutDarkThemeStyle = document.querySelector("#goldenlayout-dark-theme")! as HTMLLinkElement;
let goldenLayoutLightThemeStyle = document.querySelector("#goldenlayout-light-theme")! as HTMLLinkElement;
return document.body.classList.contains(`vscode-theme-defaults-themes-${theme}_modern-json`);
}

goldenLayoutDarkThemeStyle.disabled = light;
goldenLayoutLightThemeStyle.disabled = !light;
let updateInterval : NodeJS.Timeout;

const updatehandler = () =>
{
if(isVsCodeTheme())
{
clearInterval(updateInterval);

document.body.classList.toggle("dark", !light);
document.body.classList.toggle("light", light);

// update player theme
this.playerPanel.setTheme(theme);
}, 200);
// update golden layout theme
let goldenLayoutDarkThemeStyle = document.querySelector("#goldenlayout-dark-theme")! as HTMLLinkElement;
let goldenLayoutLightThemeStyle = document.querySelector("#goldenlayout-light-theme")! as HTMLLinkElement;

goldenLayoutDarkThemeStyle.disabled = light;
goldenLayoutLightThemeStyle.disabled = !light;

// update player theme
this.playerPanel.setTheme(theme);

document.querySelector("#pgetinker-loading")!.classList.toggle("hidden", true);
return;
}

}

updateInterval = setInterval(updatehandler, 50);
}
}

new PGEtinker();
1 change: 1 addition & 0 deletions resources/js/components/EditorPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export default class EditorPanel
if(this.autoConnect)
{
this.reconnectInterval = setInterval(reconnectHandler, 5000);
reconnectHandler();
}

this.monacoWrapper.getEditor().setValue(code);
Expand Down
2 changes: 1 addition & 1 deletion resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<link rel="stylesheet" type="text/css" href="{{ Vite::asset('resources/css/normalize.scss')}}">
<link rel="stylesheet" type="text/css" href="{{ Vite::asset('resources/css/app.scss')}}">
@vite('resources/js/app.ts')
@vite('resources/js/app-preload.ts')
</head>
<body>
<div id="app">
Expand Down
22 changes: 16 additions & 6 deletions tests/Browser/BrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public function testAgreeRevealsTheApplication(): void

$browser->click("#i-agree");

$browser->waitUntilMissing("#pgetinker-loading");
$browser->waitUntilMissing("#pgetinker-loading", 10);
$browser->assertMissing("#pgetinker-loading");

$browser->assertSee("News and Updates");
});
Expand All @@ -52,7 +53,8 @@ public function testDismissesNewsAndUpdates(): void
$this->browse(function(Browser $browser)
{
$browser->visit("/");
$browser->waitUntilMissing("#pgetinker-loading");
$browser->waitUntilMissing("#pgetinker-loading", 10);
$browser->assertMissing("#pgetinker-loading");

$browser->click(".footer .ok");
$browser->waitUntilMissing(".dialog");
Expand All @@ -66,7 +68,8 @@ public function testLoadsDefaultCodeOnClick(): void
$this->browse(function(Browser $browser)
{
$browser->visit("/");
$browser->waitUntilMissing("#pgetinker-loading");
$browser->waitUntilMissing("#pgetinker-loading", 10);
$browser->assertMissing("#pgetinker-loading");

$browser->click("@settings-menu");

Expand All @@ -86,7 +89,8 @@ public function testSelectsLightTheme(): void
$this->browse(function(Browser $browser)
{
$browser->visit("/");
$browser->waitUntilMissing("#pgetinker-loading");
$browser->waitUntilMissing("#pgetinker-loading", 10);
$browser->assertMissing("#pgetinker-loading");

$browser->click("@settings-menu");

Expand All @@ -107,7 +111,8 @@ public function testCompilesOnClick(): void
$this->browse(function(Browser $browser)
{
$browser->visit("/");
$browser->waitUntilMissing("#pgetinker-loading");
$browser->waitUntilMissing("#pgetinker-loading", 10);
$browser->assertMissing("#pgetinker-loading");

$browser->click("#start-stop");
$browser->waitFor("#player-panel .iframe-container iframe", 10);
Expand All @@ -120,14 +125,19 @@ public function testSharesOnClick(): void
$this->browse(function(Browser $browser)
{
$browser->visit("/");
$browser->waitUntilMissing("#pgetinker-loading");
$browser->waitUntilMissing("#pgetinker-loading", 10);
$browser->assertMissing("#pgetinker-loading");

$browser->mouseover("@sharing-menu");
$browser->click("#share");
$browser->waitFor(".share-dialog");

$shareUrl = $browser->value("#share-url");
$browser->visit($shareUrl);

$browser->waitUntilMissing("#pgetinker-loading", 10);
$browser->assertMissing("#pgetinker-loading");

$browser->assertSee("C++ Editor");
});
}
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default defineConfig({
'resources/css/disagreed.scss',
'resources/js/disagreed.js',
'resources/css/app.scss',
'resources/js/app.ts'
'resources/js/app-preload.ts'
],
refresh: true,
}),
Expand Down

0 comments on commit 8bda708

Please sign in to comment.