Skip to content

Commit

Permalink
Improve (#1278)
Browse files Browse the repository at this point in the history
* try to fix ResizeObserver loop completed with undelivered notifications.

* handle recrodings sync all

* handle some errors
  • Loading branch information
an-lee authored Jan 18, 2025
1 parent d88a0fd commit d36eac0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 32 deletions.
36 changes: 15 additions & 21 deletions enjoy/src/main/db/handlers/recordings-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,21 @@ class RecordingsHandler {
}

private async findOne(_event: IpcMainEvent, where: WhereOptions<Recording>) {
return Recording.scope("withoutDeleted")
.findOne({
include: PronunciationAssessment,
order: [["createdAt", "DESC"]],
where: {
...where,
},
})
.then((recording) => {
if (!recording) {
throw new Error(t("models.recording.notFound"));
}

if (!recording.isSynced) {
recording.sync();
}
const recording = await Recording.scope("withoutDeleted").findOne({
include: PronunciationAssessment,
order: [["createdAt", "DESC"]],
where: {
...where,
},
});
if (!recording) {
throw new Error(t("models.recording.notFound"));
}
if (!recording.isSynced) {
recording.sync().catch(() => {});
}

return recording.toJSON();
});
return recording.toJSON();
}

private async sync(_event: IpcMainEvent, id: string) {
Expand Down Expand Up @@ -96,9 +92,7 @@ class RecordingsHandler {
});

try {
recordings.forEach(async (recording) => {
await recording.sync();
});
await Promise.all(recordings.map((recording) => recording.sync()));
} catch (err) {
logger.error("failed to sync recordings", err.message);

Expand Down
2 changes: 1 addition & 1 deletion enjoy/src/renderer/components/login/github-login-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const GithubLoginForm = () => {
alt="github"
/>
</div>
{oauthInfo ? (
{oauthInfo?.userCode ? (
<div className="grid gap-8">
<div className="flex items-center justify-center gap-2 text-5xl">
{oauthInfo.userCode.split("").map((char, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,18 @@ export const MediaCurrentRecording = () => {
if (!ref?.current) return;
if (!player) return;

let rafId: number;
const observer = new ResizeObserver(() => {
debouncedCalContainerSize();
cancelAnimationFrame(rafId);
rafId = requestAnimationFrame(() => {
debouncedCalContainerSize();
});
});
observer.observe(ref.current);

return () => {
observer.disconnect();
cancelAnimationFrame(rafId);
};
}, [ref, player]);

Expand Down Expand Up @@ -801,13 +806,18 @@ const MediaRecorder = () => {
useEffect(() => {
if (!ref?.current) return;

let rafId: number;
const observer = new ResizeObserver(() => {
debouncedCalContainerSize();
cancelAnimationFrame(rafId);
rafId = requestAnimationFrame(() => {
debouncedCalContainerSize();
});
});
observer.observe(ref.current);

return () => {
observer.disconnect();
cancelAnimationFrame(rafId);
};
}, [ref]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,19 @@ export const MediaWaveform = () => {
setWaveformContainerRef(ref);

if (!wavesurfer) return;

let rafId: number;
const observer = new ResizeObserver(() => {
debouncedCalContainerSize();
cancelAnimationFrame(rafId);
rafId = requestAnimationFrame(() => {
debouncedCalContainerSize();
});
});
observer.observe(ref.current);

return () => {
observer.disconnect();
cancelAnimationFrame(rafId);
};
}, [ref, wavesurfer]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { useEffect, useState, useContext } from "react";
import {
AppSettingsProviderContext,
DictProviderContext,
ThemeProviderContext,
} from "@/renderer/context";
import { DictProviderContext, ThemeProviderContext } from "@/renderer/context";
import Frame, { useFrame } from "react-frame-component";
import { getExtension } from "@/utils";
import { DictDefinitionNormalizer } from "@renderer/lib/dict";
import { LoaderSpin } from "@renderer/components";
import { t } from "i18next";
import debounce from "lodash/debounce";

const MIME: Record<string, string> = {
css: "text/css",
Expand Down Expand Up @@ -137,14 +134,25 @@ export const DictLookupResultInner = ({
const [html, setHtml] = useState("");
const [hash, setHash] = useState("");

const debouncedResize = debounce(onResize, 100);

useEffect(() => {
if (autoHeight) {
let rafId: number;
const resizeObserver = new ResizeObserver(() => {
const html = innerDocument.getElementsByTagName("html")[0];
onResize(html.scrollHeight);
cancelAnimationFrame(rafId);
rafId = requestAnimationFrame(() => {
const html = innerDocument.getElementsByTagName("html")[0];
debouncedResize(html.scrollHeight);
});
});

resizeObserver.observe(innerDocument.getElementById("inner-dict"));

return () => {
resizeObserver.disconnect();
cancelAnimationFrame(rafId);
};
}
}, []);

Expand Down

0 comments on commit d36eac0

Please sign in to comment.