Refactor browserID handling. Force retaining browserID on logout
This commit is contained in:
parent
f4e39d644e
commit
d5edd2452a
@ -327,7 +327,6 @@ const loadHaForm = async () => {
|
|||||||
await card.getConfigElement();
|
await card.getConfigElement();
|
||||||
};
|
};
|
||||||
|
|
||||||
const ID_STORAGE_KEY = "browser_mod-browser-id";
|
|
||||||
const ConnectionMixin = (SuperClass) => {
|
const ConnectionMixin = (SuperClass) => {
|
||||||
class BrowserModConnection extends SuperClass {
|
class BrowserModConnection extends SuperClass {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -514,27 +513,8 @@ const ConnectionMixin = (SuperClass) => {
|
|||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
get browserID() {
|
browserIDChanged(oldID, newID) {
|
||||||
if (localStorage[ID_STORAGE_KEY])
|
|
||||||
return localStorage[ID_STORAGE_KEY];
|
|
||||||
this.browserID = "";
|
|
||||||
return this.browserID;
|
|
||||||
}
|
|
||||||
set browserID(id) {
|
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
function _createBrowserID() {
|
|
||||||
var _a, _b;
|
|
||||||
const s4 = () => {
|
|
||||||
return Math.floor((1 + Math.random()) * 100000)
|
|
||||||
.toString(16)
|
|
||||||
.substring(1);
|
|
||||||
};
|
|
||||||
return (_b = (_a = window.fully) === null || _a === void 0 ? void 0 : _a.getDeviceId()) !== null && _b !== void 0 ? _b : `${s4()}${s4()}-${s4()}${s4()}`;
|
|
||||||
}
|
|
||||||
if (id === "")
|
|
||||||
id = _createBrowserID();
|
|
||||||
const oldID = localStorage[ID_STORAGE_KEY];
|
|
||||||
localStorage[ID_STORAGE_KEY] = id;
|
|
||||||
this.fireEvent("browser-mod-config-update");
|
this.fireEvent("browser-mod-config-update");
|
||||||
if (((_a = this.browsers) === null || _a === void 0 ? void 0 : _a[oldID]) !== undefined &&
|
if (((_a = this.browsers) === null || _a === void 0 ? void 0 : _a[oldID]) !== undefined &&
|
||||||
((_b = this.browsers) === null || _b === void 0 ? void 0 : _b[this.browserID]) === undefined) {
|
((_b = this.browsers) === null || _b === void 0 ? void 0 : _b[this.browserID]) === undefined) {
|
||||||
@ -1964,6 +1944,51 @@ const AutoSettingsMixin = (SuperClass) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ID_STORAGE_KEY = "browser_mod-browser-id";
|
||||||
|
const BrowserIDMixin = (SuperClass) => {
|
||||||
|
return class BrowserIDMixinClass extends SuperClass {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
if (Storage) {
|
||||||
|
if (!Storage.prototype.browser_mod_patched) {
|
||||||
|
const _clear = Storage.prototype.clear;
|
||||||
|
Storage.prototype.clear = function () {
|
||||||
|
const browserId = this.getItem(ID_STORAGE_KEY);
|
||||||
|
const suspendWhenHidden = this.getItem("suspendWhenHidden");
|
||||||
|
_clear.apply(this);
|
||||||
|
this.setItem(ID_STORAGE_KEY, browserId);
|
||||||
|
this.setItem("suspendWhenHidden", suspendWhenHidden);
|
||||||
|
};
|
||||||
|
Storage.prototype.browser_mod_patched = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get browserID() {
|
||||||
|
if (localStorage[ID_STORAGE_KEY])
|
||||||
|
return localStorage[ID_STORAGE_KEY];
|
||||||
|
this.browserID = "";
|
||||||
|
return this.browserID;
|
||||||
|
}
|
||||||
|
set browserID(id) {
|
||||||
|
function _createBrowserID() {
|
||||||
|
var _a, _b;
|
||||||
|
const s4 = () => {
|
||||||
|
return Math.floor((1 + Math.random()) * 100000)
|
||||||
|
.toString(16)
|
||||||
|
.substring(1);
|
||||||
|
};
|
||||||
|
return (_b = (_a = window.fully) === null || _a === void 0 ? void 0 : _a.getDeviceId()) !== null && _b !== void 0 ? _b : `${s4()}${s4()}-${s4()}${s4()}`;
|
||||||
|
}
|
||||||
|
if (id === "")
|
||||||
|
id = _createBrowserID();
|
||||||
|
const oldID = localStorage[ID_STORAGE_KEY];
|
||||||
|
localStorage[ID_STORAGE_KEY] = id;
|
||||||
|
this.browserIDChanged(oldID, id);
|
||||||
|
}
|
||||||
|
browserIDChanged(oldID, newID) { }
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
- Fix nomenclature
|
- Fix nomenclature
|
||||||
@ -2012,7 +2037,7 @@ const AutoSettingsMixin = (SuperClass) => {
|
|||||||
- Media_seek
|
- Media_seek
|
||||||
- Screensavers
|
- Screensavers
|
||||||
*/
|
*/
|
||||||
class BrowserMod extends ServicesMixin(PopupMixin(ActivityMixin(BrowserStateMixin(CameraMixin(MediaPlayerMixin(ScreenSaverMixin(AutoSettingsMixin(FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget))))))))))) {
|
class BrowserMod extends ServicesMixin(PopupMixin(ActivityMixin(BrowserStateMixin(CameraMixin(MediaPlayerMixin(ScreenSaverMixin(AutoSettingsMixin(FullyMixin(RequireInteractMixin(ConnectionMixin(BrowserIDMixin(EventTarget)))))))))))) {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.connect();
|
this.connect();
|
||||||
|
47
js/plugin/browserID.ts
Normal file
47
js/plugin/browserID.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
const ID_STORAGE_KEY = "browser_mod-browser-id";
|
||||||
|
|
||||||
|
export const BrowserIDMixin = (SuperClass) => {
|
||||||
|
return class BrowserIDMixinClass extends SuperClass {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
if (Storage) {
|
||||||
|
if (!Storage.prototype.browser_mod_patched) {
|
||||||
|
const _clear = Storage.prototype.clear;
|
||||||
|
Storage.prototype.clear = function () {
|
||||||
|
const browserId = this.getItem(ID_STORAGE_KEY);
|
||||||
|
const suspendWhenHidden = this.getItem("suspendWhenHidden");
|
||||||
|
_clear.apply(this);
|
||||||
|
this.setItem(ID_STORAGE_KEY, browserId);
|
||||||
|
this.setItem("suspendWhenHidden", suspendWhenHidden);
|
||||||
|
};
|
||||||
|
Storage.prototype.browser_mod_patched = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get browserID() {
|
||||||
|
if (localStorage[ID_STORAGE_KEY]) return localStorage[ID_STORAGE_KEY];
|
||||||
|
this.browserID = "";
|
||||||
|
return this.browserID;
|
||||||
|
}
|
||||||
|
set browserID(id) {
|
||||||
|
function _createBrowserID() {
|
||||||
|
const s4 = () => {
|
||||||
|
return Math.floor((1 + Math.random()) * 100000)
|
||||||
|
.toString(16)
|
||||||
|
.substring(1);
|
||||||
|
};
|
||||||
|
return window.fully?.getDeviceId() ?? `${s4()}${s4()}-${s4()}${s4()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id === "") id = _createBrowserID();
|
||||||
|
const oldID = localStorage[ID_STORAGE_KEY];
|
||||||
|
localStorage[ID_STORAGE_KEY] = id;
|
||||||
|
|
||||||
|
this.browserIDChanged(oldID, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected browserIDChanged(oldID, newID) {}
|
||||||
|
};
|
||||||
|
};
|
@ -1,7 +1,5 @@
|
|||||||
import { hass, provideHass } from "../helpers";
|
import { hass, provideHass } from "../helpers";
|
||||||
|
|
||||||
const ID_STORAGE_KEY = "browser_mod-browser-id";
|
|
||||||
|
|
||||||
export const ConnectionMixin = (SuperClass) => {
|
export const ConnectionMixin = (SuperClass) => {
|
||||||
class BrowserModConnection extends SuperClass {
|
class BrowserModConnection extends SuperClass {
|
||||||
public hass;
|
public hass;
|
||||||
@ -202,25 +200,7 @@ export const ConnectionMixin = (SuperClass) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get browserID() {
|
browserIDChanged(oldID, newID) {
|
||||||
if (localStorage[ID_STORAGE_KEY]) return localStorage[ID_STORAGE_KEY];
|
|
||||||
this.browserID = "";
|
|
||||||
return this.browserID;
|
|
||||||
}
|
|
||||||
set browserID(id) {
|
|
||||||
function _createBrowserID() {
|
|
||||||
const s4 = () => {
|
|
||||||
return Math.floor((1 + Math.random()) * 100000)
|
|
||||||
.toString(16)
|
|
||||||
.substring(1);
|
|
||||||
};
|
|
||||||
return window.fully?.getDeviceId() ?? `${s4()}${s4()}-${s4()}${s4()}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (id === "") id = _createBrowserID();
|
|
||||||
const oldID = localStorage[ID_STORAGE_KEY];
|
|
||||||
localStorage[ID_STORAGE_KEY] = id;
|
|
||||||
|
|
||||||
this.fireEvent("browser-mod-config-update");
|
this.fireEvent("browser-mod-config-update");
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -15,6 +15,7 @@ import { PopupMixin } from "./popups";
|
|||||||
import pjson from "../../package.json";
|
import pjson from "../../package.json";
|
||||||
import "./popup-card";
|
import "./popup-card";
|
||||||
import { AutoSettingsMixin } from "./frontend-settings";
|
import { AutoSettingsMixin } from "./frontend-settings";
|
||||||
|
import { BrowserIDMixin } from "./browserID";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
@ -72,7 +73,11 @@ export class BrowserMod extends ServicesMixin(
|
|||||||
MediaPlayerMixin(
|
MediaPlayerMixin(
|
||||||
ScreenSaverMixin(
|
ScreenSaverMixin(
|
||||||
AutoSettingsMixin(
|
AutoSettingsMixin(
|
||||||
FullyMixin(RequireInteractMixin(ConnectionMixin(EventTarget)))
|
FullyMixin(
|
||||||
|
RequireInteractMixin(
|
||||||
|
ConnectionMixin(BrowserIDMixin(EventTarget))
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user