Skip to content

Commit beb4427

Browse files
committed
refactor: 移除clipboardProxy对store的依赖
1 parent 3f3cbcd commit beb4427

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

src/services/client/StorageClient.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { getAPIClient } from '../ClientFactory';
33
import type { ProgressInfo } from 'native-util';
44
import type { ProgressCallback } from '../history/HistoryTransferQueue';
55
import { clipboardContentToItem } from '@/utils/clipboard/convert';
6-
import { historyStorage } from '@/storage/HistoryStorage';
7-
import { useHistoryStore } from '@/stores/historyStore';
6+
import { historyService } from '../history/HistoryService';
87
import { prepareTempFilePath } from '@/utils/fileStorage';
98
import { calculateFileProfileHash } from '@/utils/hash';
109
import { ISyncClipboardAPI, type DownloadProgressCallback } from '@/api/clients/APIClient';
@@ -28,7 +27,7 @@ async function downloadAndAddToHistory(
2827

2928
// 仅在 profileHash 不为空时查询历史记录缓存
3029
if (content.profileHash) {
31-
const historyItem = await historyStorage.getItem(content.profileHash);
30+
const historyItem = await historyService.getItem(content.profileHash);
3231
if (historyItem?.fileUri) {
3332
const cachedFile = new File(historyItem.fileUri);
3433
if (cachedFile.exists) {
@@ -63,11 +62,11 @@ async function downloadAndAddToHistory(
6362
profileHash: profileHash || '',
6463
syncStatus: HistorySyncStatus.Synced,
6564
});
66-
await useHistoryStore.getState().addItem(item);
65+
await historyService.addItem(item);
6766

6867
// addItem 内部会将文件移动到历史目录,重新读取以获取最新的 fileUri
6968
if (profileHash) {
70-
const storedItem = await historyStorage.getItem(profileHash);
69+
const storedItem = await historyService.getItem(profileHash);
7170
if (storedItem?.fileUri) {
7271
updatedContent = { ...updatedContent, fileUri: storedItem.fileUri };
7372
}

src/utils/clipboardProxy.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import * as Clipboard from 'expo-clipboard';
1313
import { AppState, Platform } from 'react-native';
14-
import { useSettingsStore } from '@/stores/settingsStore';
14+
import { configService } from '@/services/ConfigService';
1515
import { setTimer, clearTimer } from 'native-timer';
1616
import { nativeSaveClipboardImageToFile } from 'native-util';
1717

@@ -104,7 +104,7 @@ export async function dismissOverlay(): Promise<void> {
104104
async function shouldUseOverlay(): Promise<boolean> {
105105
if (Platform.OS !== 'android' || !overlayModule) return false;
106106
if (AppState.currentState !== 'background') return false;
107-
const config = useSettingsStore.getState().config;
107+
const config = await configService.getConfig();
108108
if (!(config?.enableClipboardOverlay ?? false)) return false;
109109
// Sync overlay visibility and retry count to native module
110110
const isDebug = config?.debugMode ?? false;
@@ -124,10 +124,10 @@ async function shouldUseOverlay(): Promise<boolean> {
124124
* 条件:Android + 后台 + 设置启用 + Shizuku 可用且有权限
125125
* Shizuku 优先级高于悬浮窗
126126
*/
127-
function shouldUseShizuku(): boolean {
127+
async function shouldUseShizuku(): Promise<boolean> {
128128
if (Platform.OS !== 'android' || !shizukuModule) return false;
129129
if (AppState.currentState !== 'background') return false;
130-
const config = useSettingsStore.getState().config;
130+
const config = await configService.getConfig();
131131
if (!(config?.enableShizukuClipboard ?? false)) return false;
132132
if (!shizukuModule.isShizukuAvailable()) return false;
133133
if (!shizukuModule.hasShizukuPermission()) return false;
@@ -138,7 +138,7 @@ function shouldUseShizuku(): boolean {
138138
* 获取剪贴板文本
139139
*/
140140
export async function getStringAsync(options?: Clipboard.GetStringOptions): Promise<string> {
141-
if (shouldUseShizuku()) {
141+
if (await shouldUseShizuku()) {
142142
try {
143143
const result = await shizukuModule!.getStringViaShizuku();
144144
return result;
@@ -170,7 +170,7 @@ export async function setStringAsync(
170170
* 检查剪贴板是否有文本
171171
*/
172172
export async function hasStringAsync(): Promise<boolean> {
173-
if (shouldUseShizuku()) {
173+
if (await shouldUseShizuku()) {
174174
try {
175175
return await shizukuModule!.hasStringViaShizuku();
176176
} catch (e) {
@@ -191,7 +191,7 @@ export async function hasStringAsync(): Promise<boolean> {
191191
* 检查剪贴板是否有图片
192192
*/
193193
export async function hasImageAsync(): Promise<boolean> {
194-
if (shouldUseShizuku()) {
194+
if (await shouldUseShizuku()) {
195195
try {
196196
return await shizukuModule!.hasImageViaShizuku();
197197
} catch (e) {

0 commit comments

Comments
 (0)