chore: configure eslint and update gitignore
This commit is contained in:
48
preload.js
48
preload.js
@@ -1,5 +1,17 @@
|
||||
const { contextBridge, ipcRenderer } = require('electron');
|
||||
|
||||
// 加载jsQR库
|
||||
let jsQRLib = null;
|
||||
try {
|
||||
// 直接require jsqr模块
|
||||
const jsqrModule = require('jsqr');
|
||||
// 处理ES module的default export
|
||||
jsQRLib = jsqrModule.default || jsqrModule;
|
||||
console.log('jsQR loaded successfully:', typeof jsQRLib);
|
||||
} catch (e) {
|
||||
console.error('Failed to load jsQR:', e);
|
||||
}
|
||||
|
||||
contextBridge.exposeInMainWorld('api', {
|
||||
// Vault operations
|
||||
getVaults: () => ipcRenderer.invoke('db:getVaults'),
|
||||
@@ -17,5 +29,39 @@ contextBridge.exposeInMainWorld('api', {
|
||||
searchAccounts: (query, vaultId) => ipcRenderer.invoke('db:searchAccounts', query, vaultId),
|
||||
|
||||
// Clipboard
|
||||
copyToClipboard: (text) => ipcRenderer.invoke('clipboard:write', text)
|
||||
copyToClipboard: (text) => ipcRenderer.invoke('clipboard:write', text),
|
||||
|
||||
|
||||
// Screenshot
|
||||
captureScreen: () => ipcRenderer.invoke('screen:capture'),
|
||||
|
||||
// QR Code parsing
|
||||
decodeQR: (imageData, width, height) => {
|
||||
if (!jsQRLib) {
|
||||
console.error('jsQR not loaded');
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// 确保是Uint8ClampedArray格式
|
||||
const data = imageData instanceof Uint8ClampedArray
|
||||
? imageData
|
||||
: new Uint8ClampedArray(imageData);
|
||||
|
||||
console.log('Decoding QR, image size:', width, 'x', height, 'data length:', data.length);
|
||||
const result = jsQRLib(data, width, height);
|
||||
|
||||
if (result) {
|
||||
console.log('QR code found:', result.data);
|
||||
return result.data;
|
||||
} else {
|
||||
console.log('No QR code found in image');
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('QR decode error:', e);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
hasJsQR: () => !!jsQRLib,
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user