Skip to content

Commit

Permalink
Fix torch related bug
Browse files Browse the repository at this point in the history
Fix for #634

Issue was related to track not getting updated on camera restart.
  • Loading branch information
mebjas committed Nov 30, 2022
1 parent 55acb4b commit bed403b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion minified/html5-qrcode.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/html5-qrcode-scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,9 @@ export class Html5QrcodeScanner {
Html5QrcodeScannerStatus.STATUS_WARNING);
}
);
} else {
torchButton.updateTorchCapability(
cameraCapabilities.torchFeature());
}
torchButton.show();
};
Expand Down
14 changes: 12 additions & 2 deletions src/ui/scanner/torch-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ export interface TorchButtonOptions {
/** Helper class for creating Torch UI component. */
export class TorchButton implements TorchButtonController {
private readonly torchButton: HTMLButtonElement;
private readonly torchController: TorchController;
private readonly onTorchActionFailureCallback: OnTorchActionFailureCallback;

private torchController: TorchController;

private constructor(
torchCapability: BooleanCameraCapability,
onTorchActionFailureCallback: OnTorchActionFailureCallback) {
this.onTorchActionFailureCallback = onTorchActionFailureCallback;
this.torchButton
= BaseUiElementFactory.createElement<HTMLButtonElement>(
"button", PublicUiElementIdAndClasses.TORCH_BUTTON_ID);
Expand Down Expand Up @@ -154,11 +157,18 @@ export class TorchButton implements TorchButtonController {
$this.torchButton.classList.add(
PublicUiElementIdAndClasses.TORCH_BUTTON_CLASS_TORCH_OFF);
}
});
});

parentElement.appendChild(this.torchButton);
}

public updateTorchCapability(torchCapability: BooleanCameraCapability) {
this.torchController = new TorchController(
torchCapability,
/* buttonController= */ this,
this.onTorchActionFailureCallback);
}

/** Returns the torch button. */
public getTorchButton(): HTMLButtonElement {
return this.torchButton;
Expand Down

0 comments on commit bed403b

Please sign in to comment.