Skip to content

Commit 61e42b3

Browse files
Merge pull request #10 from AKVorrat/allow-headless
Minor changes to allow headless usage of the speedtest
2 parents a4f0d92 + 48128e2 commit 61e42b3

7 files changed

Lines changed: 25 additions & 4 deletions

File tree

assets/css/styles.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
html {
3434
scroll-behavior: smooth;
3535
overflow-x: hidden;
36-
background-color: var(--color-primary);
3736
}
3837

3938
body {

nb-speedtest/env.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,14 @@ interface ImportMetaEnv {
55

66
interface ImportMeta {
77
readonly env: ImportMetaEnv;
8-
}
8+
}
9+
10+
// Allow interaction between the speedtest and the controller process
11+
// for running this test automated in a headless browser
12+
interface Window {
13+
nbSpeedtestOptions?: {
14+
acceptedPolicy?: boolean
15+
}
16+
nbSpeedtestOnResult?: (result: any) => void
17+
nbSpeedtestOnFinished?: () => void
18+
}

nb-speedtest/src/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ const App: Component = () => {
6363
</ColsLayout>
6464
</Container>
6565
</>
66-
6766
);
6867
};
6968

nb-speedtest/src/SpeedTest.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ const NBSpeedTest: Component<{ onStateChange?: (state: SpeedTestState) => void }
9191
const newResults = [...results(), outcome]
9292
setResults(newResults)
9393

94+
if (window.nbSpeedtestOnResult) {
95+
window.nbSpeedtestOnResult({ success: outcome.success, result: outcome.success ? outcome.result.getSummary() : undefined })
96+
}
97+
9498
const nextIndex = currentIndex + 1
9599
if (nextIndex < testRuns().length) {
96100
setCurrentTest(nextIndex)
@@ -99,6 +103,10 @@ const NBSpeedTest: Component<{ onStateChange?: (state: SpeedTestState) => void }
99103
setTestRunCount(prev => prev + 1)
100104
setFinished(new Date())
101105
setTimeout(restart, config.repeatIntervalSec * 1000)
106+
107+
if (window.nbSpeedtestOnFinished) {
108+
window.nbSpeedtestOnFinished()
109+
}
102110
}
103111
}
104112

nb-speedtest/src/components/PowerBtn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const PowerBtn: Component<{ onClick?: JSX.EventHandlerUnion<HTMLButtonEle
99
<div class="p-8 bg-primary/5 rounded-full aspect-square">
1010
<div class="p-8 bg-primary/10 rounded-full aspect-square border border-primary/20">
1111
<div class="p-8 bg-primary/20 rounded-full aspect-square border border-primary/30">
12-
<button class="btn btn-circle btn-xl text-primary-content border-primary p-12 text-5xl bg-gradient-to-b from-primary to-primary/50 shadow-xl" onClick={props.onClick}>
12+
<button id="nb_speedtest_start_btn" class="btn btn-circle btn-xl text-primary-content border-primary p-12 text-5xl bg-gradient-to-b from-primary to-primary/50 shadow-xl" onClick={props.onClick}>
1313
<TbPower />
1414
<span class='sr-only'>{t.speedtest.startBtn()}</span>
1515
</button>

nb-speedtest/src/components/PrivacyPolicyModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const PrivacyPolicyModal: Component<PrivacyPolicyModalProps> = (props) =>
5555
</div>
5656
<div class="modal-action flex-col items-stretch">
5757
<button
58+
id="nb_speedtest_accept_policy"
5859
class="btn btn-primary"
5960
onClick={handleAccept}
6061
autofocus

nb-speedtest/src/util/privacy-policy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export function getPrivacyPolicyVersion(): string {
1111
}
1212

1313
export function isPrivacyPolicyAccepted(): boolean {
14+
if (window.nbSpeedtestOptions?.acceptedPolicy === true) {
15+
return true
16+
}
17+
1418
try {
1519
const stored = localStorage.getItem(STORAGE_KEY);
1620
if (!stored) {

0 commit comments

Comments
 (0)