MCPcopy Create free account
hub / github.com/CatMuse/HiNote / startWatching

Method startWatching

src/views/managers/DeviceManager.ts:32–52  ·  view source on GitHub ↗

* 开始监听屏幕尺寸变化

(element: HTMLElement)

Source from the content-addressed store, hash-verified

30 * 开始监听屏幕尺寸变化
31 */
32 startWatching(element: HTMLElement): void {
33 this.observedElement = element;
34 this.updateDeviceInfo();
35
36 // 使用 ResizeObserver 监听元素尺寸变化
37 this.resizeObserver = new ResizeObserver(() => {
38 const oldIsMobile = this.isMobileView;
39 const oldIsSmallScreen = this.isSmallScreen;
40
41 this.updateDeviceInfo();
42
43 // 如果设备信息发生变化,触发回调
44 if (oldIsMobile !== this.isMobileView || oldIsSmallScreen !== this.isSmallScreen) {
45 if (this.onDeviceChangeCallback) {
46 this.onDeviceChangeCallback(this.getDeviceInfo());
47 }
48 }
49 });
50
51 this.resizeObserver.observe(element);
52 }
53
54 /**
55 * 停止监听

Callers 1

setupHiNoteViewFunction · 0.80

Calls 2

updateDeviceInfoMethod · 0.95
getDeviceInfoMethod · 0.95

Tested by

no test coverage detected