Nerwyn/service-call-tile-feature

Support older iOS versions

ericth1 opened this issue · 4 comments

As an user of an ipad with an old (not updateable) iOS I'm unable to use this really nice feature because older iOS doesn't support java script function StructuredClone.

Current behavior:
On older iOS version < 15.4 the service call tile feature is not working properly because of the missing StructuredClone function: "Can't find variable: structuredClone"

Wish
To support older iOS version by implementing this code:

`
if (!window.structuredClone) {
function myDeepCopy(value) {
if (Array.isArray(value)) {
var count = value.length;
var arr = new Array(count);
for (var i = 0; i < count; i++) {
arr[i] = myDeepCopy(value[i]);
}

        return arr;
    } else if (typeof value === 'object') {
        var obj = {};
        for (var prop in value) {
            obj[prop] = myDeepCopy(value[prop]);
        }

        return obj;
    } else { // Primitive value
        return value;
    }
}

window.structuredClone = myDeepCopy;

}
`

See also https://www.gloomycorner.com/javascript-troubleshooting-structuredclone-is-not-defined/

Nerwyn commented

That's a pretty elegant solution. Let me implement it and create an alpha build for you to test.

Nerwyn commented

@ericth1 try this build 3.1.4-alpha.001. Because Home Assistant config objects are simple, I used a simpler clone function using JSON parse/stringify

if (!window.structuredClone) {
	window.structuredClone = (obj) => JSON.parse(JSON.stringify(obj));
}

@Nerwyn I installed the alpha version and now I can use this pretty feature also on older iOS versions. Thanks for your effort, much appreciated!

Nerwyn commented

Fixed in 3.1.4