This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
154 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import QrcodeDecoder from "qrcode-decoder" | ||
import { fs, dialog } from "@tauri-apps/api" | ||
import { state } from "../../stores/state" | ||
import { totpImageConverter, migrationImageConverter } from "../../../libraries/convert" | ||
import { navigate } from "../../../libraries/navigate" | ||
|
||
export const chooseImages = async () => { | ||
const filePaths = await dialog.open({ multiple: true, filters: [{ name: "Image file", extensions: ["jpg", "jpeg", "png", "bmp"] }] }) | ||
|
||
if (filePaths === null) { | ||
return | ||
} | ||
|
||
const images: string[] = [] | ||
|
||
for (let i = 0; i < filePaths.length; i++) { | ||
const file = await fs.readBinaryFile(filePaths[i]) | ||
|
||
const blob = new Blob([file], { type: "application/octet-binary" }) | ||
const url = URL.createObjectURL(blob) | ||
|
||
images.push(url) | ||
} | ||
|
||
let string = "" | ||
|
||
for (let i = 0; i < images.length; i++) { | ||
const processImages = async () => { | ||
const qr = new QrcodeDecoder() | ||
|
||
// decode image | ||
const res = await qr.decodeFromImage(images[i]) | ||
|
||
if (res === false) { | ||
// no qr code found | ||
// return invoke("error", { invokeMessage: "No QR code found on the picture!\n\nPlease try again with another picture!" }) | ||
} else if (res.data.startsWith("otpauth://totp/") || res.data.startsWith("otpauth-migration://")) { | ||
if (res.data.startsWith("otpauth://totp/")) { | ||
string += totpImageConverter(res.data) | ||
} else { | ||
string += migrationImageConverter(res.data) | ||
} | ||
|
||
if (images.length === i + 1) { | ||
// invoke("info", { invokeMessage: "QR code(s) found!" }) | ||
|
||
console.log(string) | ||
|
||
state.set({ importData: string }) | ||
|
||
navigate("/codes") | ||
} | ||
} else { | ||
// no qr code found | ||
// return invoke("error", { invokeMessage: "Wrong QR code found on the picture!\n\nPlease try again with another picture!" }) | ||
} | ||
} | ||
|
||
processImages() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { router } from "tinro" | ||
|
||
export const navigate = (link: string) => { | ||
router.goto(link) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters