diff --git a/scripts/clean_node_modules.sh b/scripts/clean_node_modules.sh index e489a8d..ee55993 100755 --- a/scripts/clean_node_modules.sh +++ b/scripts/clean_node_modules.sh @@ -14,7 +14,8 @@ rm -r ./{ansicolors,buffer-from,canvas-renderer,cardinal,concat-stream,core-util rm -r ./{earcut,esm,esprima,geojson-vt,gl-matrix,grid-index,ieee754,inherits,isarray,kdbush,@mapbox,minimist,murmurhash-js} rm -r ./{path-to-regexp,pbf,potpack,process-nextick-args,protocol-buffers-schema,quickselect} rm -r ./{readable-stream,redeyed,resolve-protobuf-schema,rw,safe-buffer,sharkdown,split,ssr-window,string_decoder} -rm -r ./{supercluster,template7,through,tinyqueue,topojson-client,typedarray,util-deprecate,vector-tile,vt-pbf,whatwg-fetch,wgs84} +rm -r ./{supercluster,template7,text-encoding,through,tinyqueue,topojson-client,ts-custom-error,typedarray} +rm -r ./{util-deprecate,vector-tile,vt-pbf,whatwg-fetch,wgs84} rm -r @fortawesome/fontawesome-free/{js,less,scss,sprites,svgs} rm -r @fortawesome/fontawesome-free/css/{all.css,brands.css,brands.min.css,fontawesome.css,fontawesome.min.css,regular.css,\ @@ -39,6 +40,9 @@ rm -r leaflet/dist/{leaflet.js.map,leaflet-src.esm.js,leaflet-src.esm.js.map,lea rm -r leaflet.vectorgrid/{docs,leafdoc-templates,node_modules,package.json,README.md,src} rm -r leaflet.vectorgrid/dist/{Leaflet.VectorGrid.bundled.js.map,Leaflet.VectorGrid.bundled.min.js,Leaflet.VectorGrid.js,Leaflet.VectorGrid.js.map,Leaflet.VectorGrid.min.js,vectorgrid-api-docs.html} + +rm -r @zxing/library/{esm5,CONTRIBUTING.md,README.md} +rm -r @zxing/library/umd/index.min.js.map echo "Size after: $(du -sh | cut -d ' ' -f 1)" echo "Cleanup complete!" diff --git a/www/css/app.css b/www/css/app.css index 9404e52..2ad4197 100644 --- a/www/css/app.css +++ b/www/css/app.css @@ -64,4 +64,40 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. .badges .badge i { font-size: 35px; +} + +#web-barcode-ui { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: 999999; + display: block; + background: rgba(0,0,0,0.75); +} + +#web-barcode-ui.hidden { + display: none; +} + +#web-barcode-ui video#barcode-viewer { + max-width: calc(100% - 2em); + max-height: calc(100% - 2em); + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + border-radius: 1em; +} + +#web-barcode-ui .text { + position: absolute; + left: 0; + bottom: 0; + width: 100vw; + padding: 1em 5px 1em 5px; + color: white; + text-align: center; + background: rgba(0,0,0,0.5); } \ No newline at end of file diff --git a/www/index.html b/www/index.html index 72654d5..bf1fc9d 100644 --- a/www/index.html +++ b/www/index.html @@ -27,6 +27,13 @@ + + diff --git a/www/js/home.js b/www/js/home.js index c1c664d..2f3cc56 100644 --- a/www/js/home.js +++ b/www/js/home.js @@ -47,49 +47,35 @@ function setupProfile() { } function scanCode() { - if (platform_type != "cordova") { - app.dialog.alert("You can't scan barcodes with this device.", "Sorry!"); - } - cordova.plugins.barcodeScanner.scan( - function (result) { - if (!result.cancelled) { - callAPI("code", { - username: localStorage.getItem("username"), - password: localStorage.getItem("password"), - code: result.text - }, function (resp) { - if (resp.item == "" && resp.munzee == "") { - app.dialog.alert("You didn't find anything new.", ""); - } else { - if (resp.item == "") { - $("#founditem-block").addClass("display-none"); - } else { - $("#founditem-name").text(resp.item); - $("#founditem-block").removeClass("display-none"); - } - if (resp.munzee == "") { - $("#foundmunzee-block").addClass("display-none"); - } else { - $("#foundmunzee-name").text(resp.munzee); - $("#foundmunzee-block").removeClass("display-none"); - } - app.popup.open("#founditem-popup"); - } - }, function (msg) { - app.dialog.alert(msg, "Error"); - }); + scanBarcode(function (text) { + callAPI("code", { + username: localStorage.getItem("username"), + password: localStorage.getItem("password"), + code: text + }, function (resp) { + if (resp.item == "" && resp.munzee == "") { + app.dialog.alert("You didn't find anything new.", ""); + } else { + if (resp.item == "") { + $("#founditem-block").addClass("display-none"); + } else { + $("#founditem-name").text(resp.item); + $("#founditem-block").removeClass("display-none"); } - }, - function (error) { - app.dialog.alert(error, "Scan Error"); - }, - { - showTorchButton: true, - prompt: "Find a code", - resultDisplayDuration: 0, - disableSuccessBeep: true + if (resp.munzee == "") { + $("#foundmunzee-block").addClass("display-none"); + } else { + $("#foundmunzee-name").text(resp.munzee); + $("#foundmunzee-block").removeClass("display-none"); + } + app.popup.open("#founditem-popup"); } - ); + }, function (msg) { + app.dialog.alert(msg, "Error"); + }); + }, function (error) { + app.dialog.alert(error, "Scan Error"); + }); } function openPlace(id, name) { diff --git a/www/js/platform.js b/www/js/platform.js index 3ee2d74..437bd82 100644 --- a/www/js/platform.js +++ b/www/js/platform.js @@ -14,6 +14,10 @@ var openBrowser = function (url) { } +var scanBarcode = function (success, error) { + app.dialog.alert("You can't scan barcodes with this device.", "Sorry!"); +} + var getLocation = function (success, error) { if ("geolocation" in navigator) { navigator.geolocation.getCurrentPosition(function (position) { @@ -80,6 +84,27 @@ function initCordova() { openBrowser = function (url) { cordova.InAppBrowser.open(url, '_blank', 'location=yes'); } + + scanBarcode = function (success, error) { + cordova.plugins.barcodeScanner.scan( + function (result) { + if (!result.cancelled) { + success(result.text); + } + }, + function (err) { + if (typeof error == "function") { + error(err); + } + }, + { + showTorchButton: true, + prompt: "Find a code", + resultDisplayDuration: 0, + disableSuccessBeep: true + } + ); + } } function initNW() { @@ -113,6 +138,41 @@ function initNW() { browserwin.menu = browsermenu; }); } + + $("body").append(''); + + scanBarcode = function (success, error) { + $("#web-barcode-ui").removeClass("hidden"); + // Stolen from https://zxing-js.github.io/library/examples/multi-camera/ + const codeReader = new ZXing.BrowserMultiFormatReader(); + console.log('ZXing code reader initialized'); + codeReader.getVideoInputDevices() + .then((videoInputDevices) => { + selectedDeviceId = videoInputDevices[0].deviceId; + + codeReader.decodeFromInputVideoDeviceContinuously(selectedDeviceId, 'barcode-viewer', (result, err) => { + if (result) { + console.log(result); + codeReader.reset(); + $("#web-barcode-ui").addClass("hidden"); + success(result.text); + } + if (err && !(err instanceof ZXing.NotFoundException)) { + console.error(err); + codeReader.reset(); + $("#web-barcode-ui").addClass("hidden"); + error(err); + } + }); + }) + .catch((err) => { + console.error(err); + }); + $("#web-barcode-ui").on("click", function () { + codeReader.reset(); + $("#web-barcode-ui").addClass("hidden"); + }); + }; } function initBrowser() { diff --git a/www/package.json b/www/package.json index 6142688..ab418f6 100644 --- a/www/package.json +++ b/www/package.json @@ -5,6 +5,7 @@ "license": "MPL-2.0", "dependencies": { "@fortawesome/fontawesome-free": "^5.8.1", + "@zxing/library": "^0.14.2", "framework7": "^4.3.0", "jdenticon": "^2.1.1", "jquery": "^3.4.0", diff --git a/www/yarn.lock b/www/yarn.lock index 8d13f67..d099ce1 100644 --- a/www/yarn.lock +++ b/www/yarn.lock @@ -66,6 +66,15 @@ resolved "https://registry.yarnpkg.com/@mapbox/whoots-js/-/whoots-js-3.1.0.tgz#497c67a1cef50d1a2459ba60f315e448d2ad87fe" integrity sha512-Es6WcD0nO5l+2BOQS4uLfNPYQaNDfbot3X1XUoloz+x0mPDS3eeORZJl06HXjwBG1fOGwCRnzK88LMdxKRrd6Q== +"@zxing/library@^0.14.2": + version "0.14.2" + resolved "https://registry.yarnpkg.com/@zxing/library/-/library-0.14.2.tgz#686a4218857b21e4a6c64561769d9901bf623d94" + integrity sha512-n621ErZ7tba9/7GlU6LsfbDgx1fnjZNxblwKU5W4p8vHGIJ2X+/F9rAUyHq8PAUN3HkZaelhS58qhnbbVH8SBA== + dependencies: + ts-custom-error "^3.0.0" + optionalDependencies: + text-encoding "^0.7.0" + ansicolors@~0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/ansicolors/-/ansicolors-0.2.1.tgz#be089599097b74a5c9c4a84a0cdbcdb62bd87aef" @@ -373,6 +382,11 @@ template7@^1.4.1: resolved "https://registry.yarnpkg.com/template7/-/template7-1.4.1.tgz#c3b2b03d6879e1c5f8a79067c961c8896ffaeec6" integrity sha512-sYZ9Wl5kFuNSvLcMPq8z4oenG7rDho6KnB2vWyvMJCdI1guJhxTEU0TCwr6Nd1Jx34kSOmrpJakMGxJgCc55yg== +text-encoding@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.7.0.tgz#f895e836e45990624086601798ea98e8f36ee643" + integrity sha512-oJQ3f1hrOnbRLOcwKz0Liq2IcrvDeZRHXhd9RgLrsT+DjWY/nty1Hi7v3dtkaEYbPYe0mUoOfzRrMwfXXwgPUA== + through@2: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" @@ -390,6 +404,11 @@ topojson-client@^2.1.0: dependencies: commander "2" +ts-custom-error@^3.0.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/ts-custom-error/-/ts-custom-error-3.1.0.tgz#2abcd25b253ca209036a51870318da9b1de93107" + integrity sha512-EIL1r8RKfa006lLhSSVsAlvu6/BgRdSLSxibP27zq66ydh6Kbsjv1pV7VAD7TxQfdQ9begiQW0QVjsnr9KvVrw== + typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"