Skip to content

Commit

Permalink
🐛 (llm): Keep screen awake when needed
Browse files Browse the repository at this point in the history
- App install inside My Ledger
- Firmware Update
- Inline App install => DeviceAction Component
- Sync Onboarding
  • Loading branch information
jdabbech-ledger committed Apr 23, 2024
1 parent b769d70 commit 1355189
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-swans-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

Prevent the screen from locking for firmware update and app installation/update
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { FwUpdateForegroundEvent } from "./types";
import { FwUpdateBackgroundEvent } from "~/reducers/types";
import { setLastConnectedDevice, setLastSeenDeviceInfo } from "~/actions/settings";
import { lastSeenDeviceSelector } from "~/reducers/settings";
import { useKeepScreenAwake } from "~/hooks/useKeepScreenAwake";

type Props = {
device: Device;
Expand Down Expand Up @@ -156,13 +157,17 @@ export default function FirmwareUpdate({

const onCloseAndReinstall = useCallback(() => onTryClose(true), [onTryClose]);
const onCloseSilently = useCallback(() => onTryClose(false), [onTryClose]);
const { activateKeepScreenAwake, deactivateKeepScreenAwake } = useKeepScreenAwake();

useEffect(() => {
// reset the state whenever we re-open the modal
if (isOpen) {
activateKeepScreenAwake();
onReset();
} else {
deactivateKeepScreenAwake();
}
}, [isOpen, onReset]);
}, [activateKeepScreenAwake, deactivateKeepScreenAwake, isOpen, onReset]);

useEffect(() => {
if (!nextBackgroundEvent) return;
Expand Down
21 changes: 19 additions & 2 deletions apps/ledger-live-mobile/src/screens/FirmwareUpdate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import BatteryWarningDrawer from "./BatteryWarningDrawer";
import { setLastConnectedDevice, setLastSeenDeviceInfo } from "~/actions/settings";
import { lastSeenDeviceSelector } from "~/reducers/settings";
import { BaseNavigatorStackParamList } from "~/components/RootNavigator/types/BaseNavigator";
import { useKeepScreenAwake } from "~/hooks/useKeepScreenAwake";

const requiredBatteryStatuses = [
BatteryStatusTypes.BATTERY_PERCENTAGE,
Expand Down Expand Up @@ -216,6 +217,14 @@ export const FirmwareUpdate = ({
deviceInfo,
isBeforeOnboarding,
});
const { activateKeepScreenAwake, deactivateKeepScreenAwake } = useKeepScreenAwake();

useEffect(() => {
activateKeepScreenAwake();
return () => {
deactivateKeepScreenAwake();
};
}, [activateKeepScreenAwake, deactivateKeepScreenAwake]);

const [staxImageSource, setStaxImageSource] =
useState<React.ComponentProps<typeof Image>["source"]>();
Expand All @@ -229,15 +238,23 @@ export const FirmwareUpdate = ({
[staxImageSource],
);

const quitUpdate = useCallback(() => {
const quitUpdate = useCallback(async () => {
if (!batteryRequestCompleted) cancelBatteryCheck();

deactivateKeepScreenAwake();
if (onBackFromUpdate) {
onBackFromUpdate(updateStep);
} else {
navigation.goBack();
}
}, [batteryRequestCompleted, cancelBatteryCheck, navigation, onBackFromUpdate, updateStep]);
}, [
batteryRequestCompleted,
cancelBatteryCheck,
navigation,
onBackFromUpdate,
updateStep,
deactivateKeepScreenAwake,
]);

useEffect(() => {
if (updateStep === "completed") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo, memo } from "react";
import React, { useMemo, memo, useEffect } from "react";
import type { App } from "@ledgerhq/types-live";
import type { Action, State } from "@ledgerhq/live-common/apps/index";
import { Flex } from "@ledgerhq/native-ui";
Expand All @@ -9,6 +9,7 @@ import AppUninstallButton from "./AppUninstallButton";
import AppUpdateButton from "./AppUpdateButton";

import AppProgressButton from "./AppProgressButton";
import { useKeepScreenAwake } from "~/hooks/useKeepScreenAwake";

type Props = {
app: App;
Expand Down Expand Up @@ -48,6 +49,20 @@ const AppStateButton = ({
[app.name, installed],
);

const { activateKeepScreenAwake, deactivateKeepScreenAwake } = useKeepScreenAwake();

useEffect(() => {
if (installing || uninstalling || updating) {
activateKeepScreenAwake();
} else {
deactivateKeepScreenAwake();
}

return () => {
deactivateKeepScreenAwake();
};
}, [activateKeepScreenAwake, deactivateKeepScreenAwake, installing, uninstalling, updating]);

const renderAppState = () => {
switch (true) {
case installing:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import { TrackScreen, screen } from "~/analytics";
import ContinueOnStax from "./assets/ContinueOnStax";
import type { SyncOnboardingScreenProps } from "./SyncOnboardingScreenProps";
import BackupStep from "./companionSteps/BackupStep";
import { useFocusEffect } from "@react-navigation/native";
import { useKeepScreenAwake } from "~/hooks/useKeepScreenAwake";

const { BodyText, SubtitleText } = VerticalTimeline;

Expand Down Expand Up @@ -159,6 +161,17 @@ export const SyncOnboardingCompanion: React.FC<SyncOnboardingCompanionProps> = (

const servicesConfig = useFeature("protectServicesMobile");

const { activateKeepScreenAwake, deactivateKeepScreenAwake } = useKeepScreenAwake();
useFocusEffect(
useCallback(() => {
activateKeepScreenAwake();

return () => {
deactivateKeepScreenAwake();
};
}, [activateKeepScreenAwake, deactivateKeepScreenAwake]),
);

const getNextStepKey = useCallback(
(step: CompanionStepKey) => {
if (step === CompanionStepKey.Exit) {
Expand Down

0 comments on commit 1355189

Please sign in to comment.