Commit 4c150e49 by xujie

feat: 更新代码

parent 52c2df09
File mode changed from 100644 to 100755
No preview for this file type
File mode changed from 100644 to 100755
No preview for this file type
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
import { platform } from '@electron-toolkit/utils' import { platform } from '@electron-toolkit/utils'
import Logger from 'electron-log/main' import Logger from 'electron-log/main'
import { useLibrarySDK } from './librarySDK/index.js' import { useLibrarySDK } from './librarySDK/index.js'
import { useMouseSDK } from './mouseSDK/index.js' import { useMouseSDK } from './mouseSDK/index.js'
// AI键值 // AI键值
export const AI_KEY = '42' export const AI_KEY = '42'
// M键值 // M键值
export const M_KEY = '43' export const M_KEY = '43'
// 短按,开始录音 // 短按,开始录音
export const AUDIO_SHORT_DOWN_KEY = '31' export const AUDIO_SHORT_DOWN_KEY = '31'
// 短按,结束录音 // 短按,结束录音
export const AUDIO_SHORT_UP_KEY = '32' export const AUDIO_SHORT_UP_KEY = '32'
// 长按,开始录音 // 长按,开始录音
export const AUDIO_LONG_DOWN_KEY = '21' export const AUDIO_LONG_DOWN_KEY = '21'
// 长按弹起,结束录音 // 长按弹起,结束录音
export const AUDIO_LONG_UP_KEY = '22' export const AUDIO_LONG_UP_KEY = '22'
export const setupFFI = () => { export const setupFFI = () => {
const LibrarySDK = useLibrarySDK() const LibrarySDK = useLibrarySDK()
const MouseSDK = useMouseSDK() const MouseSDK = useMouseSDK()
return { return {
initMouse(type) { initMouse(type) {
return MouseSDK.connectMouse(type) return MouseSDK.connectMouse(type)
}, },
applyMouseAuth(func = () => { }) { applyMouseAuth(func = () => { }) {
if (platform.isMacOS) { if (platform.isMacOS) {
MouseSDK.applyMouseAuth(func) MouseSDK.applyMouseAuth(func)
} else { } else {
return MouseSDK.applyMouseAuth() return MouseSDK.applyMouseAuth()
} }
}, },
releaseLd2() { releaseLd2() {
return MouseSDK.releaseLd2() return MouseSDK.releaseLd2()
}, },
setDPI(value) { setDPI(value) {
return MouseSDK.setDPI(value) return MouseSDK.setDPI(value)
}, },
onMouseClick(func = () => { }) { onMouseClick(func = () => { }) {
MouseSDK.setBleCMDCallback(func) MouseSDK.setBleCMDCallback(func)
}, },
onMousePCMData(func = () => { }) { onMousePCMData(func = () => { }) {
MouseSDK.setBleDATACallback(func) MouseSDK.setBleDATACallback(func)
}, },
setDeviceConnectCallback(func = () => { }) { setDeviceConnectCallback(func = () => { }) {
MouseSDK.setDeviceConnectCallback(func) MouseSDK.setDeviceConnectCallback(func)
}, },
/** /**
* 发送文本内容到光标 * 发送文本内容到光标
* @param {*} s * @param {*} s
* @returns * @returns
*/ */
sendEditInput(s) { sendEditInput(s) {
LibrarySDK.sendText(s) LibrarySDK.sendText(s)
}, },
computerBrightness() { computerBrightness() {
LibrarySDK.setScreenbright(20) LibrarySDK.setScreenbright(20)
}, },
computerSleep() { computerSleep() {
// 睡眠 // 睡眠
// powrprof.SetSuspendState(0, 1, 0) // powrprof.SetSuspendState(0, 1, 0)
// 休眠 // 休眠
// user32.LockWorkStation() // user32.LockWorkStation()
LibrarySDK.sleep() LibrarySDK.sleep()
}, },
// 增加亮度 // 增加亮度
addScreenBright() { addScreenBright() {
let res = LibrarySDK.getScreenbright() let res = LibrarySDK.getScreenbright()
res += 25 res += 25
if (res >= 100) { if (res >= 100) {
res = 100 res = 100
} }
LibrarySDK.setScreenbright(res) LibrarySDK.setScreenbright(res)
}, },
// 降低亮度 // 降低亮度
reduceScreenBright() { reduceScreenBright() {
let res = LibrarySDK.getScreenbright() let res = LibrarySDK.getScreenbright()
res -= 25 res -= 25
if (res <= 0) { if (res <= 0) {
res = 0 res = 0
} }
LibrarySDK.setScreenbright(res) LibrarySDK.setScreenbright(res)
}, },
// 增加音量 // 增加音量
async addVolume(step = 10) { async addVolume(step = 10) {
if (platform.isMacOS) { if (platform.isMacOS) {
LibrarySDK.addVolume() LibrarySDK.addVolume()
} else { } else {
let vol = await LibrarySDK.getVolume() let vol = await LibrarySDK.getVolume()
vol += step vol += step
if (vol > 100) { if (vol > 100) {
LibrarySDK.setVolume(100) LibrarySDK.setVolume(100)
} else { } else {
LibrarySDK.setVolume(vol) LibrarySDK.setVolume(vol)
} }
} }
}, },
async reduceVolume(step = 10) { async reduceVolume(step = 10) {
if (platform.isMacOS) { if (platform.isMacOS) {
LibrarySDK.reduceVolume() LibrarySDK.reduceVolume()
} else { } else {
let vol = await LibrarySDK.getVolume() let vol = await LibrarySDK.getVolume()
vol -= step vol -= step
if (vol < 0) { if (vol < 0) {
LibrarySDK.setVolume(0) LibrarySDK.setVolume(0)
} else { } else {
LibrarySDK.setVolume(vol) LibrarySDK.setVolume(vol)
} }
} }
}, },
// 关机 // 关机
computerClose() { computerClose() {
LibrarySDK.shutdown() LibrarySDK.shutdown()
}, },
// 显示桌面 // 显示桌面
showDesktop() { showDesktop() {
LibrarySDK.showDesktop() LibrarySDK.showDesktop()
}, },
// 获取鼠标信息 // 获取鼠标信息
getDeviceInfo() { getDeviceInfo() {
return MouseSDK.getDeviceInfo() return MouseSDK.getDeviceInfo()
}, },
// 录入sdk日志 // 录入sdk日志
setSDKLogCallback(func = () => { }) { setSDKLogCallback(func = () => { }) {
MouseSDK.setSDKLogCallback(func) MouseSDK.setSDKLogCallback(func)
} }
} }
} }
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
import AIMouseSDK_x86 from '@resources/lib/mac/intel/AIMouseSDK.node?asset' import AIMouseSDK_x86 from '@resources/lib/mac/intel/AIMouseSDK.node?asset'
import AIMouseSDK from '@resources/lib/mac/m1/AIMouseSDK.node?asset' import AIMouseSDK from '@resources/lib/mac/m1/AIMouseSDK.node?asset'
import { createRequire } from 'module' import { createRequire } from 'module'
import { isX86 } from '@main/tools/util' import { isX86 } from '@main/tools/util'
const moduleRequire = createRequire(import.meta.url) const moduleRequire = createRequire(import.meta.url)
export const useMacBluetoothSDK = () => { export const useMacBluetoothSDK = () => {
const native = moduleRequire(isX86() ? AIMouseSDK_x86 : AIMouseSDK) const native = moduleRequire(isX86() ? AIMouseSDK_x86 : AIMouseSDK)
return { return {
type: 'bluetooth', type: 'bluetooth',
initLd2() { initLd2() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// native.switchConnect(0) // native.switchConnect(0)
// native.connectBleDevice('VMouse', (type) => { // native.connectBleDevice('VMouse', (type) => {
// console.log('连接蓝牙', type) // console.log('连接蓝牙', type)
// if (type === 'success') { // if (type === 'success') {
// resolve('success') // resolve('success')
// } else { // } else {
// resolve('fail') // resolve('fail')
// } // }
// }) // })
resolve('success') resolve('success')
}) })
}, },
releaseLd2() {}, releaseLd2() {},
lotBusinessAuth(func) { lotBusinessAuth(func) {
native.lotBusinessAuth((data) => { native.lotBusinessAuth((data) => {
func(data) func(data)
}) })
}, },
getDeviceInfo() { getDeviceInfo() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
native.getDeviceInfo((err, data) => { native.getDeviceInfo((err, data) => {
if (err) { if (err) {
reject(err) reject(err)
return return
} }
resolve(data) resolve(data)
}) })
}) })
}, },
setDPI(num) { setDPI(num) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
native.setDPI(Number(num), (status) => { native.setDPI(Number(num), (status) => {
resolve() resolve()
}) })
}) })
}, },
setBleCMDCallback(func) { setBleCMDCallback(func) {
native.aiMouseSendCmdDataCallBack((data) => { native.aiMouseSendCmdDataCallBack((data) => {
func(data) func(data)
}) })
}, },
setBleDATACallback(func) { setBleDATACallback(func) {
native.recordingCallBack((data) => { native.recordingCallBack((data) => {
func(data) func(data)
}) })
}, },
setDeviceConnectCallback(func) { setDeviceConnectCallback(func) {
native.setDeviceConnectCallback((data) => { native.setDeviceConnectCallback((data) => {
func(data) func(data)
}) })
}, },
setSDKLogCallback(func) { setSDKLogCallback(func) {
native.log((data) => { native.log((data) => {
func(data) func(data)
}) })
} }
} }
} }
import Logger from 'electron-log/main' import Logger from 'electron-log/main'
import { useBluetoothSDK } from './bluetoothSDK/index' import { useBluetoothSDK } from './bluetoothSDK/index'
import { useUSBSDK } from './usbSDK/index' import { useUSBSDK } from './usbSDK/index'
import { platform } from '@electron-toolkit/utils' import { platform } from '@electron-toolkit/utils'
// AI键值 // AI键值
export const AI_KEY = '42' export const AI_KEY = '42'
// AI键长按按下 // AI键长按按下
export const AI_KEY_LONG_DOWN = '25' export const AI_KEY_LONG_DOWN = '25'
// AI键长按弹起 // AI键长按弹起
export const AI_KEY_LONG_UP = '26' export const AI_KEY_LONG_UP = '26'
// M键值 // M键值
export const M_KEY = '43' export const M_KEY = '43'
// M键长按按下 // M键长按按下
export const M_KEY_LONG_DOWN = '27' export const M_KEY_LONG_DOWN = '27'
// M键长按弹起 // M键长按弹起
export const M_KEY_LONG_UP = '28' export const M_KEY_LONG_UP = '28'
// 短按,开始录音 // 短按,开始录音
export const AUDIO_SHORT_DOWN_KEY = '31' export const AUDIO_SHORT_DOWN_KEY = '31'
// 短按,结束录音 // 短按,结束录音
export const AUDIO_SHORT_UP_KEY = '32' export const AUDIO_SHORT_UP_KEY = '32'
// 长按,开始录音 // 长按,开始录音
export const AUDIO_LONG_DOWN_KEY = '21' export const AUDIO_LONG_DOWN_KEY = '21'
// 长按弹起,结束录音 // 长按弹起,结束录音
export const AUDIO_LONG_UP_KEY = '22' export const AUDIO_LONG_UP_KEY = '22'
export const useMouseSDK = () => { export const useMouseSDK = () => {
const bluetoothSDK = useBluetoothSDK() const bluetoothSDK = useBluetoothSDK()
const usbSDK = useUSBSDK() const usbSDK = useUSBSDK()
let mouseSDK = null let mouseSDK = null
const connectMouse = async (type) => { const connectMouse = async (type) => {
Logger.log('开始初始化鼠标', type) Logger.log('开始初始化鼠标', type)
if (type === 'bluetooth') { if (type === 'bluetooth') {
Logger.log('开始初始化鼠标蓝牙') Logger.log('开始初始化鼠标蓝牙')
const res = await bluetoothSDK.initLd2() const res = await bluetoothSDK.initLd2()
if (res === 'success') { if (res === 'success') {
mouseSDK = bluetoothSDK mouseSDK = bluetoothSDK
return Promise.resolve('success') return Promise.resolve('success')
} else { } else {
return Promise.reject('蓝牙初始化失败') return Promise.reject('蓝牙初始化失败')
} }
} }
if (type === 'usb') { if (type === 'usb') {
Logger.log('开始初始化鼠标USB') Logger.log('开始初始化鼠标USB')
const res = await usbSDK.initLd2() const res = await usbSDK.initLd2()
if (res === 'success') { if (res === 'success') {
mouseSDK = usbSDK mouseSDK = usbSDK
return Promise.resolve('success') return Promise.resolve('success')
} else { } else {
return Promise.reject('USB初始化失败') return Promise.reject('USB初始化失败')
} }
} }
Logger.log('同时初始化鼠标蓝牙和USB') Logger.log('同时初始化鼠标蓝牙和USB')
const [bleStatus, usbStatus] = await Promise.all([bluetoothSDK.initLd2(), usbSDK.initLd2()]) const [bleStatus, usbStatus] = await Promise.all([bluetoothSDK.initLd2(), usbSDK.initLd2()])
if (bleStatus === 'success') { if (bleStatus === 'success') {
Logger.log('鼠标蓝牙初始化成功') Logger.log('鼠标蓝牙初始化成功')
mouseSDK = bluetoothSDK mouseSDK = bluetoothSDK
return Promise.resolve() return Promise.resolve()
} }
if (usbStatus === 'success') { if (usbStatus === 'success') {
Logger.log('鼠标USB初始化成功') Logger.log('鼠标USB初始化成功')
mouseSDK = usbSDK mouseSDK = usbSDK
return Promise.resolve() return Promise.resolve()
} }
Logger.log('鼠标SDK初始化失败') Logger.log('鼠标SDK初始化失败')
return Promise.reject('鼠标SDK初始化失败') return Promise.reject('鼠标SDK初始化失败')
} }
const applyMouseAuth = (func = () => {}) => { const applyMouseAuth = (func = () => {}) => {
if (platform.isMacOS) { if (platform.isMacOS) {
bluetoothSDK.lotBusinessAuth((data) => { bluetoothSDK.lotBusinessAuth((data) => {
func(data) func(data)
}) })
} else { } else {
return mouseSDK && mouseSDK.lotBusinessAuth() return mouseSDK && mouseSDK.lotBusinessAuth()
} }
} }
const releaseLd2 = () => { const releaseLd2 = () => {
return mouseSDK && mouseSDK.releaseLd2() return mouseSDK && mouseSDK.releaseLd2()
} }
const setBleCMDCallback = (func = () => {}) => { const setBleCMDCallback = (func = () => {}) => {
mouseSDK && mouseSDK.setBleCMDCallback(func) mouseSDK && mouseSDK.setBleCMDCallback(func)
} }
const setBleDATACallback = (func = () => {}) => { const setBleDATACallback = (func = () => {}) => {
mouseSDK && mouseSDK.setBleDATACallback(func) mouseSDK && mouseSDK.setBleDATACallback(func)
} }
const getDeviceInfo = async () => { const getDeviceInfo = async () => {
if (mouseSDK) { if (mouseSDK) {
return mouseSDK.getDeviceInfo().then((data) => { return mouseSDK.getDeviceInfo().then((data) => {
if (data) { if (data) {
return { ...data, mouseType: mouseSDK.type } return { ...data, mouseType: mouseSDK.type }
} }
return data return data
}) })
} }
return '' return ''
} }
const setDPI = (value) => { const setDPI = (value) => {
if (!mouseSDK) { if (!mouseSDK) {
throw new Error('上下文未初始化,请先调用initLd2') throw new Error('上下文未初始化,请先调用initLd2')
} }
return mouseSDK.setDPI(value) return mouseSDK.setDPI(value)
} }
const setDeviceConnectCallback = (func = () => {}) => { const setDeviceConnectCallback = (func = () => {}) => {
if (platform.isMacOS) { if (platform.isMacOS) {
bluetoothSDK.setDeviceConnectCallback((data) => { bluetoothSDK.setDeviceConnectCallback((data) => {
Logger.log('连接状态监听', data) Logger.log('连接状态监听', data)
const { status } = data const { status } = data
const type = data.type === '0' ? 'bluetooth' : 'usb' const type = data.type === '0' ? 'bluetooth' : 'usb'
func(type, status) func(type, status)
}) })
} else { } else {
bluetoothSDK.setDeviceConnectCallback((status) => { bluetoothSDK.setDeviceConnectCallback((status) => {
func('bluetooth', status) func('bluetooth', status)
}) })
usbSDK.setDeviceConnectCallback((status) => { usbSDK.setDeviceConnectCallback((status) => {
func('usb', status) func('usb', status)
}) })
} }
} }
const setSDKLogCallback = (func = () => {}) => { const setSDKLogCallback = (func = () => {}) => {
bluetoothSDK.setSDKLogCallback(func) bluetoothSDK.setSDKLogCallback(func)
} }
return { return {
releaseLd2, releaseLd2,
connectMouse, connectMouse,
setBleCMDCallback, setBleCMDCallback,
setBleDATACallback, setBleDATACallback,
getDeviceInfo, getDeviceInfo,
setDPI, setDPI,
setDeviceConnectCallback, setDeviceConnectCallback,
applyMouseAuth, applyMouseAuth,
setSDKLogCallback setSDKLogCallback
} }
} }
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
import AIMouseSDK_x86 from '@resources/lib/mac/intel/AIMouseSDK.node?asset' import AIMouseSDK_x86 from '@resources/lib/mac/intel/AIMouseSDK.node?asset'
import AIMouseSDK from '@resources/lib/mac/m1/AIMouseSDK.node?asset' import AIMouseSDK from '@resources/lib/mac/m1/AIMouseSDK.node?asset'
import { createRequire } from 'module' import { createRequire } from 'module'
const moduleRequire = createRequire(import.meta.url) const moduleRequire = createRequire(import.meta.url)
import { isX86 } from '@main/tools/util' import { isX86 } from '@main/tools/util'
export const useMacUSBSDK = () => { export const useMacUSBSDK = () => {
const native = moduleRequire(isX86() ? AIMouseSDK_x86 : AIMouseSDK) const native = moduleRequire(isX86() ? AIMouseSDK_x86 : AIMouseSDK)
return { return {
type: 'usb', type: 'usb',
initLd2() { initLd2() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// native.switchConnect(1) // native.switchConnect(1)
// native.connectUSBDevice((data) => { // native.connectUSBDevice((data) => {
// console.log('USB接收数据:', data) // console.log('USB接收数据:', data)
// if (data == 'success') { // if (data == 'success') {
// resolve('success') // resolve('success')
// } else { // } else {
// resolve('fail') // resolve('fail')
// } // }
// }) // })
resolve('success') resolve('success')
}) })
}, },
releaseLd2() {}, releaseLd2() {},
lotBusinessAuth(func) { lotBusinessAuth(func) {
native.lotBusinessAuth((data) => { native.lotBusinessAuth((data) => {
func(data) func(data)
}) })
}, },
getDeviceInfo() { getDeviceInfo() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
native.getDeviceInfo((err, data) => { native.getDeviceInfo((err, data) => {
if (err) { if (err) {
reject(err) reject(err)
return return
} }
resolve(data) resolve(data)
}) })
}) })
}, },
setDPI(num) { setDPI(num) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
native.setDPI(Number(num), (status) => { native.setDPI(Number(num), (status) => {
resolve() resolve()
}) })
}) })
}, },
setBleCMDCallback(func) { setBleCMDCallback(func) {
native.aiMouseSendCmdDataCallBack((data) => { native.aiMouseSendCmdDataCallBack((data) => {
func(data) func(data)
}) })
}, },
setBleDATACallback(func) { setBleDATACallback(func) {
native.recordingCallBack((data) => { native.recordingCallBack((data) => {
func(data) func(data)
}) })
}, },
setDeviceConnectCallback(func) { setDeviceConnectCallback(func) {
native.setDeviceConnectCallback((data) => { native.setDeviceConnectCallback((data) => {
func(data) func(data)
}) })
}, },
setSDKLogCallback(func) { setSDKLogCallback(func) {
native.log((data) => { native.log((data) => {
func(data) func(data)
}) })
} }
} }
} }
File mode changed from 100644 to 100755
...@@ -103,6 +103,7 @@ import { ...@@ -103,6 +103,7 @@ import {
MOUSE_STATUS, MOUSE_STATUS,
NOTIFY_MOUSE_CONNECT NOTIFY_MOUSE_CONNECT
} from '../../../../../eventCenter/constant' } from '../../../../../eventCenter/constant'
import { debounce } from "lodash";
const isNavigatorTool = ref(false) const isNavigatorTool = ref(false)
const sliderMaker = ref({}) const sliderMaker = ref({})
...@@ -181,7 +182,7 @@ const getInfo = async (res) => { ...@@ -181,7 +182,7 @@ const getInfo = async (res) => {
// console.log('getInfo', res) // console.log('getInfo', res)
} }
const handleSetDpi = async () => { const setCPI = async () => {
try { try {
await RSEvent.call(MOUSE_SET_DPI, dpi.value) await RSEvent.call(MOUSE_SET_DPI, dpi.value)
message.success('设置成功') message.success('设置成功')
...@@ -189,6 +190,8 @@ const handleSetDpi = async () => { ...@@ -189,6 +190,8 @@ const handleSetDpi = async () => {
message.error('设置失败') message.error('设置失败')
} }
} }
const handleSetDpi = debounce(setCPI, 800)
</script> </script>
<style lang="scss"> <style lang="scss">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment