optimizations for device id and name in apphost

This commit is contained in:
vitorsemeano 2020-11-08 23:11:22 +00:00
parent 5c58d1472f
commit 2b962124a5

View File

@ -64,51 +64,55 @@ function generateDeviceId() {
} }
function getDeviceId() { function getDeviceId() {
const key = '_deviceId2';
let deviceId = appSettings.get(key);
if (!deviceId) { if (!deviceId) {
deviceId = generateDeviceId(); const key = '_deviceId2';
appSettings.set(key, deviceId);
deviceId = appSettings.get(key);
if (!deviceId) {
deviceId = generateDeviceId();
appSettings.set(key, deviceId);
}
} }
return deviceId; return deviceId;
} }
function getDeviceName() { function getDeviceName() {
let deviceName; if (!deviceName) {
if (browser.tizen) { if (browser.tizen) {
deviceName = 'Samsung Smart TV'; deviceName = 'Samsung Smart TV';
} else if (browser.web0s) { } else if (browser.web0s) {
deviceName = 'LG Smart TV'; deviceName = 'LG Smart TV';
} else if (browser.operaTv) { } else if (browser.operaTv) {
deviceName = 'Opera TV'; deviceName = 'Opera TV';
} else if (browser.xboxOne) { } else if (browser.xboxOne) {
deviceName = 'Xbox One'; deviceName = 'Xbox One';
} else if (browser.ps4) { } else if (browser.ps4) {
deviceName = 'Sony PS4'; deviceName = 'Sony PS4';
} else if (browser.chrome) { } else if (browser.chrome) {
deviceName = 'Chrome'; deviceName = 'Chrome';
} else if (browser.edgeChromium) { } else if (browser.edgeChromium) {
deviceName = 'Edge Chromium'; deviceName = 'Edge Chromium';
} else if (browser.edge) { } else if (browser.edge) {
deviceName = 'Edge'; deviceName = 'Edge';
} else if (browser.firefox) { } else if (browser.firefox) {
deviceName = 'Firefox'; deviceName = 'Firefox';
} else if (browser.opera) { } else if (browser.opera) {
deviceName = 'Opera'; deviceName = 'Opera';
} else if (browser.safari) { } else if (browser.safari) {
deviceName = 'Safari'; deviceName = 'Safari';
} else { } else {
deviceName = 'Web Browser'; deviceName = 'Web Browser';
} }
if (browser.ipad) { if (browser.ipad) {
deviceName += ' iPad'; deviceName += ' iPad';
} else if (browser.iphone) { } else if (browser.iphone) {
deviceName += ' iPhone'; deviceName += ' iPhone';
} else if (browser.android) { } else if (browser.android) {
deviceName += ' Android'; deviceName += ' Android';
}
} }
return deviceName; return deviceName;
@ -311,8 +315,8 @@ function askForExit() {
}); });
} }
const deviceId = getDeviceId(); let deviceId;
const deviceName = getDeviceName(); let deviceName;
const appName = 'Jellyfin Web'; const appName = 'Jellyfin Web';
const appVersion = '10.7.0'; const appVersion = '10.7.0';
@ -352,15 +356,15 @@ export const appHost = {
} }
return { return {
deviceId, deviceId: getDeviceId(),
deviceName deviceName: getDeviceName()
}; };
}, },
deviceName: function () { deviceName: function () {
return window.NativeShell ? window.NativeShell.AppHost.deviceName() : deviceName; return window.NativeShell ? window.NativeShell.AppHost.deviceName() : getDeviceName();
}, },
deviceId: function () { deviceId: function () {
return window.NativeShell ? window.NativeShell.AppHost.deviceId() : deviceId; return window.NativeShell ? window.NativeShell.AppHost.deviceId() : getDeviceId();
}, },
appName: function () { appName: function () {
return window.NativeShell ? window.NativeShell.AppHost.appName() : appName; return window.NativeShell ? window.NativeShell.AppHost.appName() : appName;