@@ -12,6 +12,7 @@ import { setTimer, clearTimer } from 'native-timer';
1212import { getAPIClient } from '../ClientFactory' ;
1313import { profileDtoToContent } from '../../utils/clipboard/convert' ;
1414import { clipboardSyncState } from './SyncState' ;
15+ import { configService } from '../ConfigService' ;
1516
1617/** 远程剪贴板变化回调:仅在内容哈希变化时触发 */
1718export type RemoteClipboardChangedCallback = ( content : ClipboardContent ) => void ;
@@ -22,8 +23,6 @@ class RemoteClipboardMonitor {
2223 private callbacks = new Set < RemoteClipboardChangedCallback > ( ) ;
2324 private pollingTag : string | null = null ;
2425 private _signalRConnected = false ;
25- private _server : ServerConfig | null = null ;
26- private _pollingInterval : number | undefined = undefined ;
2726 /** 上次触发回调时的内容哈希,用于过滤重复通知 */
2827 private _lastContentHash : string | null = null ;
2928 /**
@@ -89,13 +88,14 @@ class RemoteClipboardMonitor {
8988 * 建立远程监听(SignalR 或轮询)。
9089 * 不触发初始获取,由调用方负责。
9190 */
92- async connect ( server : ServerConfig , pollingInterval ?: number ) : Promise < void > {
93- this . _server = server ;
94- this . _pollingInterval = pollingInterval ;
91+ async connect ( ) : Promise < void > {
92+ const server = await configService . getActiveServer ( ) ;
93+ if ( ! server ) return ;
94+ const config = await configService . getConfig ( ) ;
9595 if ( server . type === 'syncclipboard' ) {
9696 await this . _connectSignalR ( server ) ;
9797 } else {
98- this . _startPolling ( pollingInterval ) ;
98+ this . _startPolling ( config ?. remotePollingInterval ) ;
9999 }
100100 }
101101
@@ -104,24 +104,22 @@ class RemoteClipboardMonitor {
104104 * 若未连接则先重连,若已连接则直接刷新。
105105 * 无需区分服务器类型,内部统一处理。
106106 */
107- async resumeAndRefresh ( server : ServerConfig , pollingInterval ?: number ) : Promise < void > {
107+ async resumeAndRefresh ( ) : Promise < void > {
108108 if ( ! this . isConnected ( ) ) {
109- await this . connect ( server , pollingInterval ) ;
109+ await this . connect ( ) ;
110110 }
111111 await this . refresh ( ) ;
112112 }
113113
114114 /**
115115 * App 返回前台时由外部(RemoteClipboardMonitorTask.onForeground)调用。
116- * 使用上次已知的服务器配置重新连接并刷新 。
116+ * 重新连接并刷新 。
117117 */
118118 async handleForeground ( ) : Promise < void > {
119- if ( ! this . _server ) return ;
120- await this . resumeAndRefresh ( this . _server , this . _pollingInterval ) ;
119+ await this . resumeAndRefresh ( ) ;
121120 }
122121
123122 async disconnect ( ) : Promise < void > {
124- this . _server = null ;
125123 this . _lastContentHash = null ;
126124 this . _stopPolling ( ) ;
127125 await this . _disconnectSignalR ( ) ;
@@ -205,7 +203,6 @@ class RemoteClipboardMonitor {
205203 * @throws 无服务器连接或拉取失败时抛出异常
206204 */
207205 async fetchLatest ( ) : Promise < ClipboardContent > {
208- if ( ! this . _server ) throw new Error ( 'No active server' ) ;
209206 const apiClient = await getAPIClient ( ) ;
210207 const profile = await apiClient . getClipboard ( ) ;
211208 if ( ! profile ) throw new Error ( 'No clipboard data returned' ) ;
0 commit comments