Skip to content

Commit

Permalink
Merge pull request #995 from lbrooks/single-delay
Browse files Browse the repository at this point in the history
cleanup: Consolidate to a single `delay` method.
  • Loading branch information
alexpargon authored Feb 7, 2025
2 parents 6d9fb9e + 4673d12 commit 8032805
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 23 deletions.
5 changes: 0 additions & 5 deletions src/api/comms/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ class Device implements DeviceClass {
}
}

static delay = (ms: number) =>
new Promise(res => {
setTimeout(res, ms);
});

static getHWFVirtual = (dev: DygmaDeviceType) => {
let result: DygmaDeviceType;
Hardware.serial.forEach(hdev => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/flash/RaiseTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import log from "electron-log/renderer";
import type { SerialPort as SP } from "serialport";
import { DygmaDeviceType } from "@Renderer/types/dygmaDefs";
import { delay } from "./delay";
import { delay } from "../../main/utils/delay";
import { findDevice } from "./findDevice";
import Device from "../comms/Device";
import { arduino } from "./raiseFlasher/arduino-flasher";
Expand Down
2 changes: 1 addition & 1 deletion src/api/flash/defyFlasher/NRf52833-flasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { serialConnection, rawCommand, noWaitCommand } from "../serialConnection
import { PACKET_SIZE, TYPE_DAT, TYPE_ELA, TYPE_ESA } from "../flasherConstants";
import { HexType } from "../types";
import ihexDecode from "../ihexDecode";
import { delay } from "../delay";
import { delay } from "../../../main/utils/delay";

let serialPort;

Expand Down
2 changes: 1 addition & 1 deletion src/api/flash/defyFlasher/flash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { DeviceClass } from "@Renderer/types/devices";
import { DeviceTools } from "@Renderer/DeviceContext";
import Device, { State } from "src/api/comms/Device";
import Hardware from "../../hardware";
import { delay } from "../delay";
import { delay } from "../../../main/utils/delay";
import NRf52833 from "./NRf52833-flasher";

class FlashDefyWireless {
Expand Down
2 changes: 1 addition & 1 deletion src/api/flash/defyFlasher/rp2040-flasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import log from "electron-log/renderer";
import fs from "fs";
import * as path from "path";
import SideFlaser from "./sideFlasher";
import { delay } from "../delay";
import { delay } from "../../../main/utils/delay";

/**
* Object rp2040 with flash method.
Expand Down
2 changes: 1 addition & 1 deletion src/api/flash/defyFlasher/sideFlasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import { crc32 } from "easy-crc";
import log from "electron-log/renderer";
import type { PortInfo } from "@serialport/bindings-cpp";
import { delay } from "../delay";
import { delay } from "../../../main/utils/delay";

const { SerialPort } = eval('require("serialport")');
const { DelimiterParser } = eval('require("@serialport/parser-delimiter")');
Expand Down
2 changes: 1 addition & 1 deletion src/api/flash/raiseFlasher/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import path from "path";
import log from "electron-log/renderer";
import Focus from "../../focus";
import Hardware from "../../hardware";
import { delay } from "../delay";
import { delay } from "../../../main/utils/delay";
import formatedDate from "../formatedDate";
import { arduino } from "./arduino-flasher";

Expand Down
2 changes: 1 addition & 1 deletion src/api/flash/serialConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { PortInfo } from "@serialport/bindings-cpp";
import log from "electron-log/renderer";
import { DygmaDeviceType } from "@Renderer/types/dygmaDefs";
import type { SerialPort as SP } from "serialport";
import { delay } from "./delay";
import { delay } from "../../main/utils/delay";
import { InfoType } from "./types";
import Hardware from "../hardware";

Expand Down
2 changes: 1 addition & 1 deletion src/api/focus/Focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import log from "electron-log/renderer";
// eslint-disable-next-line import/no-cycle
import { DygmaDeviceType } from "@Renderer/types/dygmaDefs";
import { VirtualType } from "@Renderer/types/virtual";
import { delay } from "../flash/delay";
import { delay } from "../../main/utils/delay";
import { ctx } from "./Focus.ctx";

// TODO: any reason we can't import directly?
Expand Down
2 changes: 1 addition & 1 deletion src/main/utils/delay.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi, Mock } from 'vitest';
import delay from "./delay";
import { delay } from "./delay";

describe('delayed execution', () => {
let mock: Mock;
Expand Down
8 changes: 5 additions & 3 deletions src/main/utils/delay.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function delay(timeInMs: number) {
/**
* Waits the specified amount of milliseconds
* @param {number} timeInMs - The amount of time to wait in milliseconds
*/
export function delay(timeInMs: number) {
return new Promise(resolve => setTimeout(resolve, timeInMs));
}

export default delay;
2 changes: 1 addition & 1 deletion src/main/utils/listDrivesHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable @typescript-eslint/no-loop-func */
/* eslint-disable no-await-in-loop */
import log from "electron-log/main";
import delay from "./delay";
import { delay } from "./delay";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const drivelist = require("drivelist");
Expand Down
6 changes: 1 addition & 5 deletions src/renderer/controller/FlashingProcedure/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ import NRf52833 from "../../../api/flash/defyFlasher/NRf52833-flasher";
import SideFlaser from "../../../api/flash/defyFlasher/sideFlasher";
import Raise2Flash from "../../../api/flash/raise2Flasher/Raise2-flasher";
import { FlashRaise } from "../../../api/flash";
import { delay } from "../../../main/utils/delay";
import * as Context from "./context";

const delay = (ms: number) =>
new Promise(res => {
setTimeout(res, ms);
});

const stateUpdate = (stage: string, percentage: number, context: Context.ContextType) => {
log.info(stage, percentage);
let { globalProgress } = context;
Expand Down

0 comments on commit 8032805

Please sign in to comment.