Skip to content

Commit

Permalink
fix: onInternalMessage: don't fail on non-Odoo pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Tardo committed Dec 11, 2024
1 parent a0638ed commit 113152a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

```
FIX: file2base64: Support large files
FIX: onInternalMessage: Don't fail on non-Odoo pages (#141)
```

**11.7.1**
Expand Down
4 changes: 2 additions & 2 deletions src/js/common/utils/sanitize_odoo_version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

const regexVersion = /[a-z]+(?:\d+)?|[~+]|-\d+/g;
export default function (ver: string): string {
return ver?.replace(regexVersion, '');
export default function (ver: string): string | null {
return ver?.replace(regexVersion, '') || null;
}
20 changes: 14 additions & 6 deletions src/js/page/odoo/utils/get_odoo_version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ export default function (type: 'raw' | 'major' | 'minor' = 'raw'): string | numb
if (!raw) {
return;
}
const raw_split = sanitizeOdooVersion(raw).split('.');
Object.assign(cache, {
raw: raw,
major: Number(raw_split[0]),
minor: Number(raw_split[1]),
});
const raw_split = sanitizeOdooVersion(raw)?.split('.');
if (raw_split) {
Object.assign(cache, {
raw: raw,
major: Number(raw_split[0]),
minor: Number(raw_split[1]),
});
} else {
Object.assign(cache, {
raw: raw,
major: -1,
minor: -1,
});
}
}
return cache[type];
}
2 changes: 1 addition & 1 deletion src/js/private/background.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function updateBrowserAction(icon: string, text: string | null, bg_color: string
function onInternalMessage(request: Object, sender: Object) {
if (request.message === 'update_terminal_badge_info') {
const {context} = request;
const ver_clean = sanitizeOdooVersion(context.serverVersion.raw);
const ver_clean = sanitizeOdooVersion(context?.serverVersion?.raw);
if (context.isCompatible) {
ubrowser.action.enable(sender.tab.id);
let color;
Expand Down

0 comments on commit 113152a

Please sign in to comment.