大哥 主播 即时消息 三合一
This commit is contained in:
161
src/utils/pythonBridge.js
Normal file
161
src/utils/pythonBridge.js
Normal file
@@ -0,0 +1,161 @@
|
||||
// pythonBridge.js (Refactored to Electron IPC)
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { isElectron, safeElectronCall } from '@/utils/electronBridge';
|
||||
|
||||
// Check if we are in Electron environment
|
||||
const inElectron = isElectron();
|
||||
|
||||
export function usePythonBridge() {
|
||||
// ========== tk爬虫的接口 ==========
|
||||
|
||||
|
||||
// fetchDataConfig (maps to updateStartConfig)
|
||||
const fetchDataConfig = async (data) => {
|
||||
if (!inElectron) return null;
|
||||
try {
|
||||
return await window.electronAPI.tk.updateStartConfig(data);
|
||||
} catch (e) {
|
||||
console.error('fetchDataConfig error:', e);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
// fetchDataCount
|
||||
const fetchDataCount = async () => {
|
||||
if (!inElectron) return JSON.stringify({ totalCount: 0 });
|
||||
try {
|
||||
return await window.electronAPI.tk.getDataCount();
|
||||
} catch (e) {
|
||||
console.error('fetchDataCount error:', e);
|
||||
return JSON.stringify({ totalCount: 0 });
|
||||
}
|
||||
};
|
||||
|
||||
// loginTikTok
|
||||
const loginTikTok = async () => {
|
||||
if (!inElectron) return;
|
||||
await window.electronAPI.tk.loginTikTok();
|
||||
};
|
||||
|
||||
// loginBackStage
|
||||
const loginBackStage = async (data) => {
|
||||
if (!inElectron) return;
|
||||
if (data.index == 0) {
|
||||
await window.electronAPI.tk.loginBackStage(JSON.stringify(data));
|
||||
} else if (data.index == 1) {
|
||||
await window.electronAPI.tk.loginBackStageCopy(JSON.stringify(data));
|
||||
}
|
||||
};
|
||||
|
||||
// givePyAnchorId -> visitAnchor
|
||||
const givePyAnchorId = async (id) => {
|
||||
if (!inElectron) return;
|
||||
await window.electronAPI.tk.visitAnchor(id);
|
||||
};
|
||||
|
||||
// backStageloginStatus
|
||||
const backStageloginStatus = async () => {
|
||||
if (!inElectron) return null;
|
||||
return await window.electronAPI.tk.checkBackStageLoginStatus();
|
||||
};
|
||||
|
||||
// backStageloginStatusCopy
|
||||
const backStageloginStatusCopy = async () => {
|
||||
if (!inElectron) return null;
|
||||
return await window.electronAPI.tk.checkBackStageLoginStatusCopy();
|
||||
};
|
||||
|
||||
// exportToExcel
|
||||
const exportToExcel = async (data) => {
|
||||
if (!inElectron) return;
|
||||
await window.electronAPI.tk.exportData(JSON.stringify(data));
|
||||
};
|
||||
|
||||
const stopScript = async () => {
|
||||
if (!inElectron) return;
|
||||
await window.electronAPI.tk.stopCrawl();
|
||||
};
|
||||
|
||||
// getVersion
|
||||
const getVersion = async () => {
|
||||
if (!inElectron) return 'Web Mode';
|
||||
return await window.electronAPI.tk.getVersion();
|
||||
};
|
||||
|
||||
// getTkLoginStatus
|
||||
const getTkLoginStatus = async () => {
|
||||
if (!inElectron) return "false";
|
||||
return await window.electronAPI.tk.checkTkLoginStatus();
|
||||
};
|
||||
|
||||
// ========== 粉丝助手的接口 ==========
|
||||
|
||||
const controlTask = async (data) => {
|
||||
if (!inElectron) return;
|
||||
// data is JSON string in original, ensure consistent
|
||||
await window.electronAPI.tk.controlTask(data);
|
||||
};
|
||||
|
||||
const getBrotherInfo = async () => {
|
||||
if (!inElectron) return { total: 0, valid: 0 };
|
||||
const res = await window.electronAPI.tk.getBrotherInfo();
|
||||
return JSON.parse(res);
|
||||
};
|
||||
|
||||
const Specifystreaming = async (data) => {
|
||||
if (!inElectron) return;
|
||||
await window.electronAPI.tk.findBigBrother(data);
|
||||
};
|
||||
|
||||
const storageSetInfos = async (data) => {
|
||||
// data is { key, data } object
|
||||
if (!inElectron) return;
|
||||
await window.electronAPI.tk.storageSet(JSON.stringify(data));
|
||||
};
|
||||
|
||||
const readSetInfos = async (key) => {
|
||||
if (!inElectron) return "";
|
||||
const res = await window.electronAPI.tk.storageRead(JSON.stringify(key));
|
||||
return JSON.parse(res || '""'); // Handle potential empty string response
|
||||
};
|
||||
|
||||
// Maps to visitAnchor
|
||||
const openAnchorIdRooms = async (id) => {
|
||||
if (!inElectron) return;
|
||||
await window.electronAPI.tk.openRoom(id);
|
||||
};
|
||||
|
||||
// Clipboard helper - maybe use navigator.clipboard directly in Vue component?
|
||||
// Original used python bridge for clipboard.
|
||||
const setClipboards = async (text) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error('Clipboard failed', e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
fetchDataConfig,
|
||||
fetchDataCount,
|
||||
loginBackStage,
|
||||
loginTikTok,
|
||||
givePyAnchorId,
|
||||
backStageloginStatus,
|
||||
backStageloginStatusCopy,
|
||||
exportToExcel,
|
||||
stopScript,
|
||||
getVersion,
|
||||
getTkLoginStatus,
|
||||
// New Fan Workbench exports
|
||||
controlTask,
|
||||
getBrotherInfo,
|
||||
Specifystreaming,
|
||||
storageSetInfos,
|
||||
readSetInfos,
|
||||
openAnchorIdRooms,
|
||||
setClipboards
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user