Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isSupported, isTorchAvailable, isGoogleBarcodeScannerModuleAvailable should just return false by default on web, instead of throwing an exception #215

Closed
htran-ubed opened this issue Dec 13, 2024 · 3 comments

Comments

@htran-ubed
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @capacitor-mlkit/[email protected] for the project I'm working on.

Functions isSupported, isTorchAvailable, isGoogleBarcodeScannerModuleAvailable that check if functionality is available should just return false if it is not supported or not available, instead of throwing a Capacitor exception.

Here is the diff that solved my problem:

diff --git a/node_modules/@capacitor-mlkit/barcode-scanning/dist/esm/web.js b/node_modules/@capacitor-mlkit/barcode-scanning/dist/esm/web.js
index 081161f..9f2d2f5 100644
--- a/node_modules/@capacitor-mlkit/barcode-scanning/dist/esm/web.js
+++ b/node_modules/@capacitor-mlkit/barcode-scanning/dist/esm/web.js
@@ -13,7 +13,7 @@ export class BarcodeScannerWeb extends WebPlugin {
         throw this.createUnavailableException();
     }
     async isSupported() {
-        throw this.createUnavailableException();
+        return false;
     }
     async enableTorch() {
         throw this.createUnavailableException();
@@ -28,7 +28,7 @@ export class BarcodeScannerWeb extends WebPlugin {
         throw this.createUnavailableException();
     }
     async isTorchAvailable() {
-        throw this.createUnavailableException();
+        return false;        
     }
     async setZoomRatio(_options) {
         throw this.createUnavailableException();
@@ -46,7 +46,7 @@ export class BarcodeScannerWeb extends WebPlugin {
         throw this.createUnavailableException();
     }
     async isGoogleBarcodeScannerModuleAvailable() {
-        throw this.createUnavailableException();
+        return false;
     }
     async installGoogleBarcodeScannerModule() {
         throw this.createUnavailableException();

This issue body was partially generated by patch-package.

@robingenz
Copy link
Member

Thank you for creating this request. It's common to throw an exception if a method is not available on a specific platform. You can just wrap that call in a try-catch. No need to patch/fork the plugin. I'm therefore closing this issue as not planned.

@robingenz robingenz closed this as not planned Won't fix, can't repro, duplicate, stale Dec 13, 2024
@htran-ubed
Copy link
Author

isSupported should be available on all platforms. It makes no sense to have to wrap such in try catch.

@robingenz
Copy link
Member

Feel free to create a PR for that method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants