Skip to content

Commit 6e56c38

Browse files
committed
perf: add INPUT_ACTIVE event
1 parent 65a1fb2 commit 6e56c38

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/app/elements/iframe/iframe.component.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class ElementIframeComponent implements OnInit, AfterViewInit, OnDestroy
4949
ping: number;
5050
debug = false;
5151
trustedUrl: SafeResourceUrl;
52+
private lastSendInputActiveTime = 0;
5253

5354
constructor(
5455
private _i18n: I18nService,
@@ -140,6 +141,8 @@ export class ElementIframeComponent implements OnInit, AfterViewInit, OnDestroy
140141
case 'KEYBOARDEVENT':
141142
case 'MOUSEEVENT':
142143
this.renewalTrigger.next();
144+
// Lion 组件 默认会发送的 KEYBOARDEVENT 和 MOUSEEVENT
145+
this.sendInputActiveToOtherViews();
143146
break;
144147
case 'CREATE_FILE_CONNECT_TOKEN':
145148
this.createFileConnectToken.emit(true);
@@ -154,6 +157,9 @@ export class ElementIframeComponent implements OnInit, AfterViewInit, OnDestroy
154157
this.view.terminalContentData = msg.data;
155158
this._iframeSvc.sendMessage({ name: 'TERMINAL_CONTENT_RESPONSE', data: msg.data });
156159
break;
160+
case 'INPUT_ACTIVE':
161+
// KOKO 新定义的 input 事件,给所有其他 view 发送 sendInputActive 函数续期
162+
this.sendInputActiveToOtherViews();
157163
}
158164
}.bind(this);
159165

@@ -243,4 +249,30 @@ export class ElementIframeComponent implements OnInit, AfterViewInit, OnDestroy
243249
this.handleIframeEvent();
244250
}, 100);
245251
}
252+
253+
sendInputActive() {
254+
this._logger.info(`[Luna] Send Input_ACTIVE to: ${this.id}`);
255+
this.iframeWindow.postMessage({ name: 'INPUT_ACTIVE', data: "" }, '*');
256+
}
257+
258+
sendInputActiveToOtherViews() {
259+
const currentTime = Date.now();
260+
const minInterval = 10000; // 10秒间隔
261+
262+
// 检查是否已经过了最少10秒间隔
263+
if (currentTime - this.lastSendInputActiveTime < minInterval) {
264+
return; // 如果间隔不足10秒,直接返回
265+
}
266+
267+
// 更新最后发送时间
268+
this.lastSendInputActiveTime = currentTime;
269+
270+
// 遍历所有 view,给除了当前 view 之外的其他 view 发送 sendInputActive
271+
this._viewSvc.viewList.forEach(view => {
272+
if (view.id !== this.view.id && view.termComp && typeof view.termComp.sendInputActive === 'function') {
273+
view.termComp.sendInputActive();
274+
}
275+
});
276+
}
277+
246278
}

0 commit comments

Comments
 (0)