Skip to content

Commit

Permalink
Merge pull request #231 from yuque/feat/optimization
Browse files Browse the repository at this point in the history
fix: 优化插件内存
  • Loading branch information
moshangqi committed Dec 25, 2023
2 parents ea2d50b + e20330b commit 5bcc146
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
.headerWrapper {
flex: 0 0 auto;
display: flex;
padding: 16px 10px 0;
gap: 30px;
padding: 16px 18px 0;
gap: 20px;

.headerItem {
cursor: pointer;
Expand All @@ -53,7 +53,7 @@
flex: 0 0 auto;

.title {
padding: 0 16px;
padding: 0 24px;
color: @text-primary;
font-weight: 500;
font-size: @font-size-lg;
Expand Down
2 changes: 1 addition & 1 deletion src/components/lake-editor/template-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const templateHtml = `
height: 100%;
}
.ne-layout-mode-fixed .ne-engine, .ne-layout-mode-adapt .ne-engine {
padding: 16px 16px 0;
padding: 16px 24px 0;
min-height: calc(100vh - 10px)
}
.ne-layout-mode-fixed .ne-editor-wrap-content {
Expand Down
21 changes: 21 additions & 0 deletions src/pages/inject/WordMark/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, {
useEffect,
useImperativeHandle,
useRef,
useState,
} from 'react';
import {
EDITOR_IFRAME_CONTAINER_ID,
Expand Down Expand Up @@ -75,6 +76,7 @@ const getRequestID = (() => {
export default forwardRef<IEditorRef, {}>((props, ref) => {
const iframeRef = useRef<HTMLIFrameElement>(null);
const sendMessageRef = useRef<(data: any) => Promise<any>>();
const [needLoadEditor, setNeedLoadEditor] = useState(true);

useEffect(() => {
const resolveCache: Map<number, (data: any) => void> = new Map();
Expand Down Expand Up @@ -169,6 +171,25 @@ export default forwardRef<IEditorRef, {}>((props, ref) => {
[sendMessage],
);

useEffect(() => {
// 当页面可见性发生改变时,如果发现用户未使用过插件,释放掉 editor iframe
const onVisibilitychange = () => {
if (document.hidden) {
setNeedLoadEditor(false);
} else {
setNeedLoadEditor(true);
}
};
document.addEventListener('visibilitychange', onVisibilitychange);
return () => {
document.removeEventListener('visibilitychange', onVisibilitychange);
};
}, []);

if (!needLoadEditor) {
return null;
}

return (
<iframe
src={chrome.runtime.getURL('editor.html')}
Expand Down

0 comments on commit 5bcc146

Please sign in to comment.