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