mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-03-01 12:59:36 +00:00
fix bug with manual form submission where a part does not exist but decodes properly which causes the camera to not redraw on page reload due to unclean shutdown. this is an existing bug in the scanner interface.
steps to produce the issue: - have camera active - put in code in Input - info mode ticked - click submit button on page reload the camera does not reactivate
This commit is contained in:
parent
4865f07a09
commit
c5ea4d243f
1 changed files with 24 additions and 0 deletions
|
|
@ -30,6 +30,7 @@ export default class extends Controller {
|
|||
_submitting = false;
|
||||
_lastDecodedText = "";
|
||||
_onInfoChange = null;
|
||||
_onFormSubmit = null;
|
||||
|
||||
connect() {
|
||||
// Prevent double init if connect fires twice
|
||||
|
|
@ -44,6 +45,22 @@ export default class extends Controller {
|
|||
info.addEventListener("change", this._onInfoChange);
|
||||
}
|
||||
|
||||
// Stop camera cleanly before manual form submit (prevents broken camera after reload)
|
||||
const form = document.getElementById("scan_dialog_form");
|
||||
if (form) {
|
||||
this._onFormSubmit = () => {
|
||||
try {
|
||||
const p = this._scanner?.clear?.();
|
||||
if (p && typeof p.then === "function") p.catch(() => {});
|
||||
} catch (_) {
|
||||
// ignore
|
||||
}
|
||||
};
|
||||
|
||||
// capture=true so we run before other handlers / navigation
|
||||
form.addEventListener("submit", this._onFormSubmit, { capture: true });
|
||||
}
|
||||
|
||||
const isMobile = window.matchMedia("(max-width: 768px)").matches;
|
||||
|
||||
//This function ensures, that the qrbox is 70% of the total viewport
|
||||
|
|
@ -90,6 +107,13 @@ export default class extends Controller {
|
|||
}
|
||||
this._onInfoChange = null;
|
||||
|
||||
// remove the onForm submit handler
|
||||
const form = document.getElementById("scan_dialog_form");
|
||||
if (form && this._onFormSubmit) {
|
||||
form.removeEventListener("submit", this._onFormSubmit, { capture: true });
|
||||
}
|
||||
this._onFormSubmit = null;
|
||||
|
||||
if (!scanner) return;
|
||||
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue