Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions extensions/qr-code-scanner/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions extensions/qr-code-scanner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"dependencies": {
"@raycast/api": "^1.26.3",
"jimp": "^0.16.1",
"open": "^8.4.0",
"qrcode-reader": "^1.0.4"
"jsqr": "^1.4.0",
"open": "^8.4.0"
},
"devDependencies": {
"@types/node": "~16.10.0",
Expand Down
27 changes: 11 additions & 16 deletions extensions/qr-code-scanner/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
import { exec } from "child_process";
import open from "open";
import { read as decodeImage } from "jimp";
import qrcodeReader from "qrcode-reader";
import { randomInt } from "crypto";
import jsQR from "jsqr";

function qrDecode(filepath: string, callback: (data: string | boolean) => void) {
decodeImage(filepath, (err, image) => {
Expand All @@ -23,21 +23,16 @@ function qrDecode(filepath: string, callback: (data: string | boolean) => void)
showToast(ToastStyle.Failure, "Image decoder error...");
return;
}
const decodeQR = new qrcodeReader();
decodeQR.callback = function (errorWhenDecodeQR, result) {
if (errorWhenDecodeQR) {
if (errorWhenDecodeQR.indexOf("Couldn't find enough finder patterns") > -1) {
callback(false);
} else {
showToast(ToastStyle.Failure, "Parser error...");
return;
}
} else {
callback(JSON.parse(JSON.stringify(result)).result);
}
exec("rm " + filepath);
};
decodeQR.decode(image.bitmap);
const result = jsQR(new Uint8ClampedArray(image.bitmap.data.buffer), image.bitmap.width, image.bitmap.height, {
inversionAttempts: "attemptBoth",
});
if (result) {
const decoder = new TextDecoder("shift-jis");
const code = decoder.decode(Uint8Array.from(result?.binaryData).buffer);
callback(code);
return;
}
callback(false);
});
}

Expand Down