Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit f85a8870 authored by Simon Chan's avatar Simon Chan
Browse files

refactor(demo): rename GlobalState

parent af3e1633
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ import AdbWsBackend from '@yume-chan/adb-backend-ws';
import AdbWebCredentialStore from '@yume-chan/adb-credential-web';
import { observer } from 'mobx-react-lite';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { globalState } from '../state';
import { GlobalState } from '../state';
import { CommonStackTokens, Icons } from '../utils';

const DropdownStyles = { dropdown: { width: '100%' } };
@@ -33,7 +33,7 @@ function _Connect(): JSX.Element | null {
            setSupported(supported);

            if (!supported) {
                globalState.showErrorDialog('Your browser does not support WebUSB standard, which is required for this site to work.\n\nLatest version of Google Chrome, Microsoft Edge, or other Chromium-based browsers are required.');
                GlobalState.showErrorDialog('Your browser does not support WebUSB standard, which is required for this site to work.\n\nLatest version of Google Chrome, Microsoft Edge, or other Chromium-based browsers are required.');
                return;
            }

@@ -153,18 +153,18 @@ function _Connect(): JSX.Element | null {
            readable = streams.readable
                .pipeThrough(
                    new InspectStream(packet => {
                        globalState.appendLog('in', packet);
                        GlobalState.appendLog('in', packet);
                    })
                );

            writable = pipeFrom(
                streams.writable,
                new InspectStream((packet: AdbPacketInit) => {
                    globalState.appendLog('out', packet);
                    GlobalState.appendLog('out', packet);
                })
            );
        } catch (e: any) {
            globalState.showErrorDialog(e);
            GlobalState.showErrorDialog(e);
            setConnecting(false);
            return;
        }
@@ -174,7 +174,7 @@ function _Connect(): JSX.Element | null {
            // so manually close them.
            try { readable.cancel(); } catch { }
            try { await writable.close(); } catch { }
            globalState.setDevice(undefined, undefined);
            GlobalState.setDevice(undefined, undefined);
        }

        try {
@@ -187,13 +187,13 @@ function _Connect(): JSX.Element | null {
            device.disconnected.then(async () => {
                await dispose();
            }, async (e) => {
                globalState.showErrorDialog(e);
                GlobalState.showErrorDialog(e);
                await dispose();
            });

            globalState.setDevice(selectedBackend, device);
            GlobalState.setDevice(selectedBackend, device);
        } catch (e: any) {
            globalState.showErrorDialog(e);
            GlobalState.showErrorDialog(e);
            await dispose();
        } finally {
            setConnecting(false);
@@ -202,10 +202,10 @@ function _Connect(): JSX.Element | null {

    const disconnect = useCallback(async () => {
        try {
            await globalState.device!.close();
            globalState.setDevice(undefined, undefined);
            await GlobalState.device!.close();
            GlobalState.setDevice(undefined, undefined);
        } catch (e: any) {
            globalState.showErrorDialog(e);
            GlobalState.showErrorDialog(e);
        }
    }, []);

@@ -268,7 +268,7 @@ function _Connect(): JSX.Element | null {
            tokens={{ childrenGap: 8, padding: '0 0 8px 8px' }}
        >
            <Dropdown
                disabled={!!globalState.device || backendOptions.length === 0}
                disabled={!!GlobalState.device || backendOptions.length === 0}
                label="Available devices"
                placeholder="No available devices"
                options={backendOptions}
@@ -278,7 +278,7 @@ function _Connect(): JSX.Element | null {
                onChange={handleSelectedBackendChange}
            />

            {!globalState.device
            {!GlobalState.device
                ? (
                    <Stack horizontal tokens={CommonStackTokens}>
                        <StackItem grow shrink>
+3 −3
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ import { DemoMode, DemoModeMobileDataType, DemoModeMobileDataTypes, DemoModeSign
import { autorun, makeAutoObservable, reaction, runInAction } from "mobx";
import { observer } from "mobx-react-lite";
import { CSSProperties, useCallback } from 'react';
import { globalState } from "../state";
import { GlobalState } from "../state";

const SignalStrengthOptions =
    Object.values(DemoModeSignalStrength)
@@ -70,7 +70,7 @@ class DemoModePanelState {
        makeAutoObservable(this);

        reaction(
            () => globalState.device,
            () => GlobalState.device,
            async (device) => {
                if (device) {
                    runInAction(() => this.demoMode = new DemoMode(device));
@@ -329,7 +329,7 @@ export const DemoModePanel = observer(({
        <div style={{ padding: 12, overflow: 'hidden auto', ...style }}>
            <Toggle
                label="Allowed"
                disabled={!globalState.device}
                disabled={!GlobalState.device}
                checked={state.allowed}
                onChange={handleAllowedChange}
            />
+4 −4
Original line number Diff line number Diff line
import { Dialog, DialogFooter, DialogType, PrimaryButton } from '@fluentui/react';
import { observer } from "mobx-react-lite";
import { PropsWithChildren } from 'react';
import { globalState } from '../state';
import { GlobalState } from '../state';

export const ErrorDialogProvider = observer((props: PropsWithChildren<{}>) => {
    return (
@@ -9,15 +9,15 @@ export const ErrorDialogProvider = observer((props: PropsWithChildren<{}>) => {
            {props.children}

            <Dialog
                hidden={!globalState.errorDialogVisible}
                hidden={!GlobalState.errorDialogVisible}
                dialogContentProps={{
                    type: DialogType.normal,
                    title: 'Error',
                    subText: globalState.errorDialogMessage,
                    subText: GlobalState.errorDialogMessage,
                }}
            >
                <DialogFooter>
                    <PrimaryButton text="OK" onClick={globalState.hideErrorDialog} />
                    <PrimaryButton text="OK" onClick={GlobalState.hideErrorDialog} />
                </DialogFooter>
            </Dialog>
        </>
+5 −5
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ import { action, autorun, makeAutoObservable, observable, runInAction } from "mo
import { observer } from "mobx-react-lite";
import { NextPage } from "next";
import Head from "next/head";
import { globalState } from "../state";
import { GlobalState } from "../state";
import { RouteStackProps, saveFile } from "../utils";

class BugReportState {
@@ -32,10 +32,10 @@ class BugReportState {
        });

        autorun(() => {
            if (globalState.device) {
            if (GlobalState.device) {
                runInAction(() => {
                    this.bugReport = new BugReport(globalState.device!);
                    this.bugReportZ = new BugReportZ(globalState.device!);
                    this.bugReport = new BugReport(GlobalState.device!);
                    this.bugReportZ = new BugReportZ(GlobalState.device!);

                    this.bugReportZ.version().then(action(version => {
                        this.bugReportZVersion = version;
@@ -75,7 +75,7 @@ class BugReportState {
                : undefined
        );

        const sync = await globalState.device!.sync();
        const sync = await GlobalState.device!.sync();
        await sync.read(filename)
            .pipeTo(saveFile('bugreport.zip'));

+6 −6
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ import type { NextPage } from 'next';
import Head from 'next/head';
import React from "react";
import { ExternalLink } from "../components";
import { globalState } from '../state';
import { GlobalState } from '../state';
import { Icons, RouteStackProps } from "../utils";

const KNOWN_FEATURES: Record<string, string> = {
@@ -52,7 +52,7 @@ const DeviceInfo: NextPage = () => {
            </MessageBar>
            <span>
                <span>Protocol Version: </span>
                <code>{globalState.device?.protocolVersion?.toString(16).padStart(8, '0')}</code>
                <code>{GlobalState.device?.protocolVersion?.toString(16).padStart(8, '0')}</code>
            </span>
            <Separator />

@@ -60,21 +60,21 @@ const DeviceInfo: NextPage = () => {
                <code>ro.product.name</code>
                <span> field in Android Build Props</span>
            </MessageBar>
            <span>Product Name: {globalState.device?.product}</span>
            <span>Product Name: {GlobalState.device?.product}</span>
            <Separator />

            <MessageBar>
                <code>ro.product.model</code>
                <span> field in Android Build Props</span>
            </MessageBar>
            <span>Model Name: {globalState.device?.model}</span>
            <span>Model Name: {GlobalState.device?.model}</span>
            <Separator />

            <MessageBar>
                <code>ro.product.device</code>
                <span> field in Android Build Props</span>
            </MessageBar>
            <span>Device Name: {globalState.device?.device}</span>
            <span>Device Name: {GlobalState.device?.device}</span>
            <Separator />

            <MessageBar>
@@ -87,7 +87,7 @@ const DeviceInfo: NextPage = () => {
            </MessageBar>
            <span>
                <span>Features: </span>
                {globalState.device?.features?.map((feature, index) => (
                {GlobalState.device?.features?.map((feature, index) => (
                    <span key={feature}>
                        {index !== 0 && (<span>, </span>)}
                        <span>{feature}</span>
Loading