capacitor-community / barcode-scanner

A fast and efficient (QR) barcode scanner for Capacitor
MIT License
437 stars 172 forks source link

Capacitor 4.0 upgrade #137

Closed AshleyMedway closed 2 years ago

AshleyMedway commented 2 years ago

Related issue #132

Contains all changes as per https://github.com/ionic-team/create-capacitor-plugin/commit/03027bf603626ebfdba084cb9d9a1a359d008554#diff-e2254fe4747e978652de2fa9da3ad44a5195a2e0dd35e121b70435f07f93b7b6

thegnuu commented 2 years ago

Thanks a lot for this @AshleyMedway, I was just about to start with this changes!

I will make a few test and merge your changes!

AshleyMedway commented 2 years ago

@thegnuu No problem, we have a few of our own plugins so thought I could contribute to some as I had to make the sames changes about 6 times today :)

thegnuu commented 2 years ago

@AshleyMedway I was able to merge your changes (I had to do it "manually" since non-signed commits are somehow blocked in this repo).

On Android everything works as expected, but on iOS I receive the following warning:

Main Thread Checker: UI API called on a background thread: -[UIView initWithFrame:]
PID: 16320, TID: 10397992, Thread name: (none), Queue name: bridge, QoS: 0
Backtrace:
4   CapacitorCommunityBarcodeScanner    0x00000001023668b0 $s32CapacitorCommunityBarcodeScanner0cD0C10CameraViewC5frameAESo6CGRectV_tcfc + 224
5   CapacitorCommunityBarcodeScanner    0x000000010236691c $s32CapacitorCommunityBarcodeScanner0cD0C10CameraViewC5frameAESo6CGRectV_tcfcTo + 64
6   CapacitorCommunityBarcodeScanner    0x00000001023667c4 $s32CapacitorCommunityBarcodeScanner0cD0C10CameraViewC5frameAESo6CGRectV_tcfC + 104
7   CapacitorCommunityBarcodeScanner    0x000000010236a084 $s32CapacitorCommunityBarcodeScanner0cD0C4loadyyF + 440
8   CapacitorCommunityBarcodeScanner    0x000000010236a2e4 $s32CapacitorCommunityBarcodeScanner0cD0C4loadyyFTo + 36
9   CapacitorCommunityBarcodeScanner    0x000000010236c7ac $s32CapacitorCommunityBarcodeScanner0cD0C4scan33_E9781981B91FA2D5C67BE1318BC971C3LLyyF + 324
10  CapacitorCommunityBarcodeScanner    0x00000001023703dc $s32CapacitorCommunityBarcodeScanner0cD0C13startScanningyySo13CAPPluginCallCF + 276
11  CapacitorCommunityBarcodeScanner    0x000000010237042c $s32CapacitorCommunityBarcodeScanner0cD0C13startScanningyySo13CAPPluginCallCFTo + 52
12  Capacitor                           0x0000000102469cd0 $s9Capacitor0A6BridgeC12handleJSCall4callyAA0D0V_tFyycfU_ + 816
13  Capacitor                           0x000000010245f220 $sIeg_IeyB_TR + 52
14  libdispatch.dylib                   0x0000000102670c70 _dispatch_call_block_and_release + 32
15  libdispatch.dylib                   0x00000001026727c0 _dispatch_client_callout + 20
16  libdispatch.dylib                   0x000000010267a8a4 _dispatch_lane_serial_drain + 984
17  libdispatch.dylib                   0x000000010267b5e0 _dispatch_lane_invoke + 428
18  libdispatch.dylib                   0x0000000102688168 _dispatch_workloop_worker_thread + 908
19  libsystem_pthread.dylib             0x000000021d0640bc _pthread_wqthread + 288
20  libsystem_pthread.dylib             0x000000021d063e5c start_wqthread + 8
2022-08-02 15:57:07.969761+0200 App[16320:10397992] [reports] Main Thread Checker: UI API called on a background thread: -[UIView initWithFrame:]
PID: 16320, TID: 10397992, Thread name: (none), Queue name: bridge, QoS: 0
Backtrace:
4   CapacitorCommunityBarcodeScanner    0x00000001023668b0 $s32CapacitorCommunityBarcodeScanner0cD0C10CameraViewC5frameAESo6CGRectV_tcfc + 224
5   CapacitorCommunityBarcodeScanner    0x000000010236691c $s32CapacitorCommunityBarcodeScanner0cD0C10CameraViewC5frameAESo6CGRectV_tcfcTo + 64
6   CapacitorCommunityBarcodeScanner    0x00000001023667c4 $s32CapacitorCommunityBarcodeScanner0cD0C10CameraViewC5frameAESo6CGRectV_tcfC + 104
7   CapacitorCommunityBarcodeScanner    0x000000010236a084 $s32CapacitorCommunityBarcodeScanner0cD0C4loadyyF + 440
8   CapacitorCommunityBarcodeScanner    0x000000010236a2e4 $s32CapacitorCommunityBarcodeScanner0cD0C4loadyyFTo + 36
9   CapacitorCommunityBarcodeScanner    0x000000010236c7ac $s32CapacitorCommunityBarcodeScanner0cD0C4scan33_E9781981B91FA2D5C67BE1318BC971C3LLyyF + 324
10  CapacitorCommunityBarcodeScanner    0x00000001023703dc $s32CapacitorCommunityBarcodeScanner0cD0C13startScanningyySo13CAPPluginCallCF + 276
11  CapacitorCommunityBarcodeScanner    0x000000010237042c $s32CapacitorCommunityBarcodeScanner0cD0C13startScanningyySo13CAPPluginCallCFTo + 52
12  Capacitor                           0x0000000102469cd0 $s9Capacitor0A6BridgeC12handleJSCall4callyAA0D0V_tFyycfU_ + 816
13  Capacitor                           0x000000010245f220 $sIeg_IeyB_TR + 52
14  libdispatch.dylib                   0x0000000102670c70 _dispatch_call_block_and_release + 32
15  libdispatch.dylib                   0x00000001026727c0 _dispatch_client_callout + 20
16  libdispatch.dylib                   0x000000010267a8a4 _dispatch_lane_serial_drain + 984
17  libdispatch.dylib                   0x000000010267b5e0 _dispatch_lane_invoke + 428
18  libdispatch.dylib                   0x0000000102688168 _dispatch_workloop_worker_thread + 908
19  libsystem_pthread.dylib             0x000000021d0640bc _pthread_wqthread + 288
20  libsystem_pthread.dylib             0x000000021d063e5c start_wqthread + 8

The plugin still works, but initialising it takes longer somehow and this message will sure lead to a lot of new issues created even if the plugin works ;) I am currently on vacation until August 22nd and I am not sure when I will find time to resolve this issue...

I pushed my current changes to https://github.com/capacitor-community/barcode-scanner/tree/capacitor-v4, maybe someone will find time to have a look at this before I do...

AshleyMedway commented 2 years ago

Awesome thanks, I will take a look into those warnings :)

thegnuu commented 2 years ago

Great, thanks a lot! I was not able to find a part where those calls are not dispatched to the main thread with DispatchQueue.main.async but I did not spent a lot of time searching for it...

thegnuu commented 2 years ago

I think i just found the issue, the problem was introduces by PR #131 on this line https://github.com/capacitor-community/barcode-scanner/blob/capacitor-v4/ios/Plugin/Plugin.swift#L280

I am not sure if wrapping this call would be enough to prevent the issue and fix PR #131 as well?

DispatchQueue.main.async {
    self.load();
}

It would be really cool if you @AshleyMedway or @scr2em would find a few minutes to test this out!

Thanks a lot for your help!

nunoarruda commented 2 years ago

@thegnuu you are on the right track. I had the same issue with another capacitor plugin. See https://github.com/cuongpl/capacitor-ios-autofill-save-password/pull/6/commits/ec2d3a530cba2e80f4f04a5d2cab2e6702f69fa6

thegnuu commented 2 years ago

I updated the branch https://github.com/capacitor-community/barcode-scanner/tree/capacitor-v4 and it should all work now, "unfortunately" I am still on vacation and I am not able to test my changes on hardware devices.... If anyone of you can test my changes on Android and iOS it would be awesome! Otherwise I will create a release next week.

bc-m commented 2 years ago

If you could release an alpha version, I would like to test it. Gladly after your vacation. Your recreation has priority! ☺️

nunoarruda commented 2 years ago

@BC-M you can test it by installing the branch like so:

npm install --save https://github.com/capacitor-community/barcode-scanner/tree/capacitor-v4

rendyproklamanta commented 2 years ago

Hello I'm using ReactJS not TS and capacitor version 4.0.1. Try to yarn add from branch capacitor-v4 but show this error :

$ yarn add https://github.com/capacitor-community/barcode-scanner#capacitor-v4
yarn add v1.22.19
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
$ npm run build

> @capacitor-community/barcode-scanner@2.2.1 build
> npm run clean && tsc && rollup -c rollup.config.js

> @capacitor-community/barcode-scanner@2.2.1 clean
> rimraf ./dist

../../../../../../../node_modules/@types/inquirer/index.d.ts:17:28 - error TS7016: Could not find a declaration file for module 'rxjs'. 'C:/Users/MSIRTX/node_modules/rxjs/dist/cjs/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/rxjs` if it exists or add a new declaration (.d.ts) file containing `declare module 'rxjs';`

17 import { Observable } from 'rxjs';
                              ~~~~~~

../../../../../../../node_modules/@types/inquirer/lib/prompts/base.d.ts:2:28 - error TS7016: Could not find a declaration file for module 'rxjs'. 'C:/Users/MSIRTX/node_modules/rxjs/dist/cjs/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/rxjs` if it exists or add a new declaration (.d.ts) file containing `declare module 'rxjs';`

2 import { Observable } from 'rxjs';
                             ~~~~~~

../../../../../../../node_modules/@types/inquirer/lib/prompts/editor.d.ts:2:39 - error TS7016: Could not find a declaration file for module 'rxjs'. 'C:/Users/MSIRTX/node_modules/rxjs/dist/cjs/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/rxjs` if it exists or add a new declaration (.d.ts) file containing `declare module 'rxjs';`

2 import { Subject, Subscription } from 'rxjs';
                                        ~~~~~~

../../../../../../../node_modules/@types/inquirer/lib/ui/prompt.d.ts:1:28 - error TS7016: Could not find a declaration file for module 'rxjs'. 'C:/Users/MSIRTX/node_modules/rxjs/dist/cjs/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/rxjs` if it exists or add a new declaration (.d.ts) file containing `declare module 'rxjs';
hauserkristof commented 2 years ago

I have tried it, and it it working properly, after fixing a small bug by #142

Thank you all for the fast reaction and update to Capacitor 4! ☺️

thegnuu commented 2 years ago

@hauserkristof thanks a lot for your help! I will have a look at it tomorrow and publish v3 asap!

thegnuu commented 2 years ago

@rendyproklamanta thank you as well, i will check out your problem as far as I am able to atm and verify that there are no deps that are not required if this issue is cause by the plugin :)

josuelmm commented 2 years ago

Reference to property 'savedCall' in closure requires explicit use of 'self' to make capture semantics explicit Line 283 and Plugin.Swift

hauserkristof commented 2 years ago

Yes @josuelmm , thats true, but is easy to fix, and there is a PR solving that issue ( #142 )

thegnuu commented 2 years ago

I just released v3, thanks to everyone that helped on this issue!