Skip to content

Commit

Permalink
Qrcode port (#141)
Browse files Browse the repository at this point in the history
* Qrcode port

* Add cache flag

* tweaks
  • Loading branch information
iBicha authored Sep 8, 2023
1 parent 0703d74 commit 976d5a3
Show file tree
Hide file tree
Showing 42 changed files with 1,608 additions and 2,087 deletions.
7 changes: 6 additions & 1 deletion playlet-lib/src/components/Dialog/LoginDialog.bs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ function OnUrlSet()
url = m.top.url

m.urlLabel.text = url
StartAsyncTask(GenerateQrCodeTask, { qrPoster: m.qrCode, text: url })
StartAsyncTask(GenerateQrCodeTask, {
poster: m.qrCode,
text: url,
size: m.qrCode.loadWidth,
padding: 10
})
end function

function OnAuthTokenChange()
Expand Down
5 changes: 3 additions & 2 deletions playlet-lib/src/components/Dialog/LoginDialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
wrap="true" width="400">
<Font role="font" uri="font:SystemFontFile" size="24" />
</Label>
<QRPoster
<Poster
id='QrCodePoster'
width='300'
height='300'
loadWidth='300'
loadHeight='300'
loadPadding='10'
translation="[50, 50]" />
<Label
id="urlLabel"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
import "pkg:/source/QrCode/QrImage.bs"
import "pkg:/source/utils/StringUtils.bs"

@asynctask
function GenerateQrCodeTask(input as object)
' TODO:P1 QR Code generation is happening on UI thread and is hanging for a second
' Needs to be properly decoupled from Node logic
qrPoster = input.qrPoster
poster = input.poster
mode = input.mode
text = input.text
qrPoster.text = text
size = input.size
padding = input.padding

if mode = invalid
mode = QrCode.QRMode.Byte
end if

if size = invalid
size = 200
end if

if padding = invalid
padding = 0
end if

qr = new QrCode.QRImage()
imagePath = qr.Generate(text, size, padding, mode)

if not StringUtils.IsNullOrEmpty(imagePath)
poster.uri = imagePath
end if
end function
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ function OnUrlSet()
urlLabel = m.top.findNode("urlLabel")
urlLabel.text = url

qrCode = m.top.findNode("QrCodePoster")
StartAsyncTask(GenerateQrCodeTask, { qrPoster: qrCode, text: url })
qrCodePoster = m.top.findNode("QrCodePoster")
StartAsyncTask(GenerateQrCodeTask, {
poster: qrCodePoster,
text: url,
size: qrCodePoster.loadWidth,
padding: 20
})
end function
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
translation="[0,92]"
text="Scan the QR code with your phone camera, or open the URL in a web browser:"
/>
<QRPoster
<Poster
id='QrCodePoster'
loadWidth='400'
height='400'
width='400'
loadHeight='400'
loadPadding='20'
loadWidth='400'
translation='[440, 160]' />

<Label
Expand Down
1 change: 0 additions & 1 deletion playlet-lib/src/components/lib/QRCode/CREDITS.txt

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 976d5a3

Please sign in to comment.