diff --git a/dashboard-ui/apiclient/alt/deferred.js b/dashboard-ui/apiclient/alt/deferred.js deleted file mode 100644 index b17c683e34..0000000000 --- a/dashboard-ui/apiclient/alt/deferred.js +++ /dev/null @@ -1,314 +0,0 @@ -(function (global) { - function isArray(arr) { - return Object.prototype.toString.call(arr) === '[object Array]'; - } - - function foreach(arr, handler) { - if (isArray(arr)) { - for (var i = 0; i < arr.length; i++) { - handler(arr[i]); - } - } - else - handler(arr); - } - - function D(fn) { - var status = 'pending', - doneFuncs = [], - failFuncs = [], - progressFuncs = [], - resultArgs = null, - - promise = { - done: function () { - for (var i = 0; i < arguments.length; i++) { - // skip any undefined or null arguments - if (!arguments[i]) { - continue; - } - - if (isArray(arguments[i])) { - var arr = arguments[i]; - for (var j = 0; j < arr.length; j++) { - // immediately call the function if the deferred has been resolved - if (status === 'resolved') { - arr[j].apply(this, resultArgs); - } - - doneFuncs.push(arr[j]); - } - } - else { - // immediately call the function if the deferred has been resolved - if (status === 'resolved') { - arguments[i].apply(this, resultArgs); - } - - doneFuncs.push(arguments[i]); - } - } - - return this; - }, - - fail: function () { - for (var i = 0; i < arguments.length; i++) { - // skip any undefined or null arguments - if (!arguments[i]) { - continue; - } - - if (isArray(arguments[i])) { - var arr = arguments[i]; - for (var j = 0; j < arr.length; j++) { - // immediately call the function if the deferred has been resolved - if (status === 'rejected') { - arr[j].apply(this, resultArgs); - } - - failFuncs.push(arr[j]); - } - } - else { - // immediately call the function if the deferred has been resolved - if (status === 'rejected') { - arguments[i].apply(this, resultArgs); - } - - failFuncs.push(arguments[i]); - } - } - - return this; - }, - - always: function () { - return this.done.apply(this, arguments).fail.apply(this, arguments); - }, - - progress: function () { - for (var i = 0; i < arguments.length; i++) { - // skip any undefined or null arguments - if (!arguments[i]) { - continue; - } - - if (isArray(arguments[i])) { - var arr = arguments[i]; - for (var j = 0; j < arr.length; j++) { - // immediately call the function if the deferred has been resolved - if (status === 'pending') { - progressFuncs.push(arr[j]); - } - } - } - else { - // immediately call the function if the deferred has been resolved - if (status === 'pending') { - progressFuncs.push(arguments[i]); - } - } - } - - return this; - }, - - then: function () { - // fail callbacks - if (arguments.length > 1 && arguments[1]) { - this.fail(arguments[1]); - } - - // done callbacks - if (arguments.length > 0 && arguments[0]) { - this.done(arguments[0]); - } - - // notify callbacks - if (arguments.length > 2 && arguments[2]) { - this.progress(arguments[2]); - } - }, - - promise: function (obj) { - if (obj == null) { - return promise; - } else { - for (var i in promise) { - obj[i] = promise[i]; - } - return obj; - } - }, - - state: function () { - return status; - }, - - debug: function () { - console.log('[debug]', doneFuncs, failFuncs, status); - }, - - isRejected: function () { - return status === 'rejected'; - }, - - isResolved: function () { - return status === 'resolved'; - }, - - pipe: function (done, fail, progress) { - return D(function (def) { - foreach(done, function (func) { - // filter function - if (typeof func === 'function') { - deferred.done(function () { - var returnval = func.apply(this, arguments); - // if a new deferred/promise is returned, its state is passed to the current deferred/promise - if (returnval && typeof returnval === 'function') { - returnval.promise().then(def.resolve, def.reject, def.notify); - } - else { // if new return val is passed, it is passed to the piped done - def.resolve(returnval); - } - }); - } - else { - deferred.done(def.resolve); - } - }); - - foreach(fail, function (func) { - if (typeof func === 'function') { - deferred.fail(function () { - var returnval = func.apply(this, arguments); - - if (returnval && typeof returnval === 'function') { - returnval.promise().then(def.resolve, def.reject, def.notify); - } else { - def.reject(returnval); - } - }); - } - else { - deferred.fail(def.reject); - } - }); - }).promise(); - } - }, - - deferred = { - resolveWith: function (context) { - if (status === 'pending') { - status = 'resolved'; - var args = resultArgs = (arguments.length > 1) ? arguments[1] : []; - for (var i = 0; i < doneFuncs.length; i++) { - doneFuncs[i].apply(context, args); - } - } - return this; - }, - - rejectWith: function (context) { - if (status === 'pending') { - status = 'rejected'; - var args = resultArgs = (arguments.length > 1) ? arguments[1] : []; - for (var i = 0; i < failFuncs.length; i++) { - failFuncs[i].apply(context, args); - } - } - return this; - }, - - notifyWith: function (context) { - if (status === 'pending') { - var args = resultArgs = (arguments.length > 1) ? arguments[1] : []; - for (var i = 0; i < progressFuncs.length; i++) { - progressFuncs[i].apply(context, args); - } - } - return this; - }, - - resolve: function () { - return this.resolveWith(this, arguments); - }, - - reject: function () { - return this.rejectWith(this, arguments); - }, - - notify: function () { - return this.notifyWith(this, arguments); - } - } - - var obj = promise.promise(deferred); - - if (fn) { - fn.apply(obj, [obj]); - } - - return obj; - } - - D.when = function () { - if (arguments.length < 2) { - var obj = arguments.length ? arguments[0] : undefined; - if (obj && (typeof obj.isResolved === 'function' && typeof obj.isRejected === 'function')) { - return obj.promise(); - } - else { - return D().resolve(obj).promise(); - } - } - else { - return (function (args) { - var df = D(), - size = args.length, - done = 0, - rp = new Array(size); // resolve params: params of each resolve, we need to track down them to be able to pass them in the correct order if the master needs to be resolved - - for (var i = 0; i < args.length; i++) { - (function (j) { - var obj = null; - - if (args[j].done) { - args[j].done(function () { rp[j] = (arguments.length < 2) ? arguments[0] : arguments; if (++done == size) { df.resolve.apply(df, rp); } }) - .fail(function () { df.reject(arguments); }); - } else { - obj = args[j]; - args[j] = new Deferred(); - - args[j].done(function () { rp[j] = (arguments.length < 2) ? arguments[0] : arguments; if (++done == size) { df.resolve.apply(df, rp); } }) - .fail(function () { df.reject(arguments); }).resolve(obj); - } - })(i); - } - - return df.promise(); - })(arguments); - } - } - - global.Deferred = D; -})(window); - -(function (globalScope) { - - globalScope.DeferredBuilder = { - - Deferred: function () { - return new globalScope.Deferred(); - }, - - when: function (promises) { - - return globalScope.Deferred.when(promises); - } - - }; - -})(window); \ No newline at end of file diff --git a/dashboard-ui/apiclient/connectionmanager.js b/dashboard-ui/apiclient/connectionmanager.js index 350bce0ea1..f7f1be2c06 100644 --- a/dashboard-ui/apiclient/connectionmanager.js +++ b/dashboard-ui/apiclient/connectionmanager.js @@ -1148,7 +1148,7 @@ return; } - require(['connectservice'], function () { + require(['connectservice', 'cryptojs-md5'], function () { var md5 = self.getConnectPasswordHash(password); @@ -1208,7 +1208,7 @@ return; } - require(['connectservice'], function () { + require(['connectservice', 'cryptojs-md5'], function () { var md5 = self.getConnectPasswordHash(password); diff --git a/dashboard-ui/apiclient/device.js b/dashboard-ui/apiclient/device.js deleted file mode 100644 index 16f33e7e7b..0000000000 --- a/dashboard-ui/apiclient/device.js +++ /dev/null @@ -1,35 +0,0 @@ -(function (globalScope) { - - if (!globalScope.MediaBrowser) { - globalScope.MediaBrowser = {}; - } - - globalScope.MediaBrowser.generateDeviceId = function (keyName, seed) { - - keyName = keyName || 'randomId'; - - var keys = []; - - keys.push(navigator.userAgent); - keys.push((navigator.cpuClass || "")); - - if (seed) { - keys.push(seed); - } - var randomId = ''; - - // Since the above is not guaranteed to be unique per device, add a little more - randomId = appStorage.getItem(keyName); - - if (!randomId) { - - randomId = new Date().getTime(); - - appStorage.setItem(keyName, randomId.toString()); - } - - keys.push(randomId); - return CryptoJS.SHA1(keys.join('|')).toString(); - }; - -})(window); \ No newline at end of file diff --git a/dashboard-ui/bower_components/doc-ready/.bower.json b/dashboard-ui/bower_components/doc-ready/.bower.json index adda4287b4..d4d75eca65 100644 --- a/dashboard-ui/bower_components/doc-ready/.bower.json +++ b/dashboard-ui/bower_components/doc-ready/.bower.json @@ -39,6 +39,6 @@ "commit": "cec8e49744a1e18b14a711eea77e201bb70de544" }, "_source": "git://github.com/desandro/doc-ready.git", - "_target": "1.0.x", + "_target": "~1.0.4", "_originalSource": "doc-ready" } \ No newline at end of file diff --git a/dashboard-ui/bower_components/iron-flex-layout/.bower.json b/dashboard-ui/bower_components/iron-flex-layout/.bower.json index 846bf5c150..0985b733c6 100644 --- a/dashboard-ui/bower_components/iron-flex-layout/.bower.json +++ b/dashboard-ui/bower_components/iron-flex-layout/.bower.json @@ -28,14 +28,14 @@ "iron-component-page": "polymerelements/iron-component-page#^1.0.0" }, "ignore": [], - "homepage": "https://github.com/polymerelements/iron-flex-layout", + "homepage": "https://github.com/PolymerElements/iron-flex-layout", "_release": "1.2.2", "_resolution": { "type": "version", "tag": "v1.2.2", "commit": "41c4f35be1368afb770312b907a258175565dbdf" }, - "_source": "git://github.com/polymerelements/iron-flex-layout.git", + "_source": "git://github.com/PolymerElements/iron-flex-layout.git", "_target": "^1.0.0", - "_originalSource": "polymerelements/iron-flex-layout" + "_originalSource": "PolymerElements/iron-flex-layout" } \ No newline at end of file diff --git a/dashboard-ui/bower_components/iron-selector/.bower.json b/dashboard-ui/bower_components/iron-selector/.bower.json index 52d44c1907..ebb18c5b7b 100644 --- a/dashboard-ui/bower_components/iron-selector/.bower.json +++ b/dashboard-ui/bower_components/iron-selector/.bower.json @@ -36,7 +36,7 @@ "tag": "v1.0.8", "commit": "e9a66727f3da0446f04956d4e4f1dcd51cdec2ff" }, - "_source": "git://github.com/PolymerElements/iron-selector.git", + "_source": "git://github.com/polymerelements/iron-selector.git", "_target": "^1.0.0", - "_originalSource": "PolymerElements/iron-selector" + "_originalSource": "polymerelements/iron-selector" } \ No newline at end of file diff --git a/dashboard-ui/components/imagestore.js b/dashboard-ui/components/imagestore.js index bf49ad53f3..7736c58b2a 100644 --- a/dashboard-ui/components/imagestore.js +++ b/dashboard-ui/components/imagestore.js @@ -178,6 +178,8 @@ window.ImageStore = self; } - new imageFileStore(); + require(['cryptojs-sha1'], function () { + new imageFileStore(); + }); })(); \ No newline at end of file diff --git a/dashboard-ui/cordova/android/iap.js b/dashboard-ui/cordova/android/iap.js index 31e45722c4..6993947592 100644 --- a/dashboard-ui/cordova/android/iap.js +++ b/dashboard-ui/cordova/android/iap.js @@ -130,15 +130,20 @@ return; } - testDeviceId(device.uuid).then(function (isUnlocked) { + var legacyDeviceId = NativeIapManager.getLegacyDeviceId(); + if (legacyDeviceId) { + testDeviceId(legacyDeviceId).then(function(isUnlocked) { - if (isUnlocked) { - deferred.resolveWith(null, [true]); - return; - } + if (isUnlocked) { + deferred.resolveWith(null, [true]); + return; + } + deferred.resolveWith(null, [false]); + }); + } else { deferred.resolveWith(null, [false]); - }); + } }); } diff --git a/dashboard-ui/cordova/imagestore.js b/dashboard-ui/cordova/imagestore.js index 6b22f4673b..83fe8886e5 100644 --- a/dashboard-ui/cordova/imagestore.js +++ b/dashboard-ui/cordova/imagestore.js @@ -149,6 +149,8 @@ window.ImageStore = self; } - new indexedDbBlobImageStore(); + require(['cryptojs-sha1'], function () { + new indexedDbBlobImageStore(); + }); })(); \ No newline at end of file diff --git a/dashboard-ui/scripts/dashboardpage.js b/dashboard-ui/scripts/dashboardpage.js index 4e6e51a891..20aa09a12c 100644 --- a/dashboard-ui/scripts/dashboardpage.js +++ b/dashboard-ui/scripts/dashboardpage.js @@ -1308,7 +1308,7 @@ $(document).on('pageshow', "#dashboardPage", DashboardPage.onPageShow).on('pageb function takeTour(page, userId) { - Dashboard.loadSwipebox().then(function () { + require(['swipebox'], function () { $.swipebox([ { href: 'css/images/tour/dashboard/dashboard.png', title: Globalize.translate('DashboardTourDashboard') }, diff --git a/dashboard-ui/scripts/indexpage.js b/dashboard-ui/scripts/indexpage.js index 0d3aa45402..c0aedf3cf9 100644 --- a/dashboard-ui/scripts/indexpage.js +++ b/dashboard-ui/scripts/indexpage.js @@ -165,7 +165,7 @@ function takeTour(page, userId) { - Dashboard.loadSwipebox().then(function () { + require(['swipebox'], function () { $.swipebox([ { href: 'css/images/tour/web/tourcontent.jpg', title: Globalize.translate('WebClientTourContent') }, diff --git a/dashboard-ui/scripts/photos.js b/dashboard-ui/scripts/photos.js index 98c1ecac71..c57de1c690 100644 --- a/dashboard-ui/scripts/photos.js +++ b/dashboard-ui/scripts/photos.js @@ -154,7 +154,7 @@ index = 0; } - Dashboard.loadSwipebox().then(function () { + require(['swipebox'], function () { $.swipebox(slideshowItems, { initialIndexOnArray: index, diff --git a/dashboard-ui/scripts/site.js b/dashboard-ui/scripts/site.js index 51769395dd..e21820c80e 100644 --- a/dashboard-ui/scripts/site.js +++ b/dashboard-ui/scripts/site.js @@ -1522,71 +1522,6 @@ var Dashboard = { } }, - getAppInfo: function (appName, appVersion, deviceId, deviceName) { - - function generateDeviceName() { - - var name; - - if (browserInfo.chrome) { - name = "Chrome"; - } else if (browserInfo.edge) { - name = "Edge"; - } else if (browserInfo.mozilla) { - name = "Firefox"; - } else if (browserInfo.msie) { - name = "Internet Explorer"; - } else { - name = "Web Browser"; - } - - if (browserInfo.version) { - name += " " + browserInfo.version; - } - - if (browserInfo.ipad) { - name += " Ipad"; - } else if (browserInfo.iphone) { - name += " Iphone"; - } else if (browserInfo.android) { - name += " Android"; - } - return name; - } - - appVersion = appVersion || window.dashboardVersion; - appName = appName || "Emby Web Client"; - - deviceName = deviceName || generateDeviceName(); - - var seed = []; - var keyName = 'randomId'; - - deviceId = deviceId || MediaBrowser.generateDeviceId(keyName, seed.join(',')); - - return { - appName: appName, - appVersion: appVersion, - deviceName: deviceName, - deviceId: deviceId - }; - }, - - loadSwipebox: function () { - - var deferred = DeferredBuilder.Deferred(); - - Dashboard.importCss('bower_components/swipebox/src/css/swipebox.min.css'); - - require([ - 'bower_components/swipebox/src/js/jquery.swipebox.min' - ], function () { - - deferred.resolve(); - }); - return deferred.promise(); - }, - ready: function (fn) { Dashboard.initPromise.then(fn); @@ -1915,9 +1850,11 @@ var AppInfo = {}; paths: paths }); + define("cryptojs-sha1", ["apiclient/sha1"]); + define("cryptojs-md5", ["apiclient/md5"]); } - function init(promiseResolve, capabilities, appName, appVersion, deviceId, deviceName) { + function init(promiseResolve, hostingAppInfo) { if (Dashboard.isRunningInCordova() && browserInfo.android) { define("appstorage", ["cordova/android/appstorage"]); @@ -2019,7 +1956,7 @@ var AppInfo = {}; return Hammer; }); - define("cryptojs-sha1", ["apiclient/sha1"]); + define("swipebox", ['bower_components/swipebox/src/js/jquery.swipebox.min', "css!bower_components/swipebox/src/css/swipebox.min.css"]); define("contentuploader", ["apiclient/sync/contentuploader"]); define("serversync", ["apiclient/sync/serversync"]); @@ -2037,10 +1974,6 @@ var AppInfo = {}; var deps = []; - if (!deviceId) { - deps.push('cryptojs-sha1'); - } - if (!window.fetch) { deps.push('bower_components/fetch/fetch'); } @@ -2053,16 +1986,15 @@ var AppInfo = {}; require(deps, function () { - var baseInfo = Dashboard.getAppInfo(appName, appVersion, deviceId, deviceName); - for (var i in baseInfo) { - AppInfo[i] = baseInfo[i]; + for (var i in hostingAppInfo) { + AppInfo[i] = hostingAppInfo[i]; } - initAfterDependencies(promiseResolve, capabilities); + initAfterDependencies(promiseResolve); }); } - function initAfterDependencies(promiseResolve, capabilities) { + function initAfterDependencies(promiseResolve) { var drawer = document.querySelector('.mainDrawerPanel'); drawer.classList.remove('mainDrawerPanelPreInit'); @@ -2093,7 +2025,6 @@ var AppInfo = {}; deps.push('apiclient/connectionmanager'); deps.push('apiclient/deferred'); deps.push('apiclient/credentials'); - deps.push('apiclient/md5'); deps.push('thirdparty/jquerymobile-1.4.5/jquery.mobile.custom.js'); @@ -2132,6 +2063,8 @@ var AppInfo = {}; } } + var capabilities = Dashboard.capabilities(); + capabilities.DeviceProfile = MediaPlayer.getDeviceProfile(Math.max(screen.height, screen.width)); var connectionManagerPromise = createConnectionManager(capabilities); @@ -2273,34 +2206,97 @@ var AppInfo = {}; } } - function initCordovaWithDeviceId(deferred, deviceId) { + function getCordovaHostingAppInfo() { - cordova.getAppVersion.getVersionNumber(function (appVersion) { - var capablities = Dashboard.capabilities(); + return new Promise(function (resolve, reject) { - var name = browserInfo.android ? "Emby for Android Mobile" : (browserInfo.safari ? "Emby for iOS" : "Emby Mobile"); + document.addEventListener("deviceready", function () { - // Remove special characters - var cleanDeviceName = device.model.replace(/[^\w\s]/gi, ''); + cordova.getAppVersion.getVersionNumber(function (appVersion) { - init(deferred, capablities, name, appVersion, deviceId, cleanDeviceName); + var name = browserInfo.android ? "Emby for Android Mobile" : (browserInfo.safari ? "Emby for iOS" : "Emby Mobile"); + + // Remove special characters + var cleanDeviceName = device.model.replace(/[^\w\s]/gi, ''); + + resolve({ + deviceId: device.uuid, + deviceName: cleanDeviceName, + appName: name, + appVersion: appVersion + }); + + }); + + }, false); }); } - function initCordova(deferred) { + function getWebHostingAppInfo() { - document.addEventListener("deviceready", function () { + return new Promise(function (resolve, reject) { - window.plugins.uniqueDeviceID.get(function (uuid) { + var deviceName; - initCordovaWithDeviceId(deferred, uuid); + if (browserInfo.chrome) { + deviceName = "Chrome"; + } else if (browserInfo.edge) { + deviceName = "Edge"; + } else if (browserInfo.mozilla) { + deviceName = "Firefox"; + } else if (browserInfo.msie) { + deviceName = "Internet Explorer"; + } else { + deviceName = "Web Browser"; + } - }, function () { + if (browserInfo.version) { + deviceName += " " + browserInfo.version; + } - // Failure. Use cordova uuid - initCordovaWithDeviceId(deferred, device.uuid); - }); - }, false); + if (browserInfo.ipad) { + deviceName += " Ipad"; + } else if (browserInfo.iphone) { + deviceName += " Iphone"; + } else if (browserInfo.android) { + deviceName += " Android"; + } + + function onDeviceAdAcquired(id) { + + resolve({ + deviceId: id, + deviceName: deviceName, + appName: "Emby Web Client", + appVersion: window.dashboardVersion + }); + } + + var deviceId = appStorage.getItem('_deviceId'); + + if (deviceId) { + onDeviceAdAcquired(deviceId); + } else { + require(['cryptojs-md5'], function () { + var keys = []; + keys.push(navigator.userAgent); + keys.push((navigator.cpuClass || "")); + + var randomId = CryptoJS.SHA1(keys.join('|')).toString(); + appStorage.setItem('_deviceId', randomId); + onDeviceAdAcquired(randomId); + }); + } + }); + } + + function getHostingAppInfo() { + + if (Dashboard.isRunningInCordova()) { + return getCordovaHostingAppInfo(); + } + + return getWebHostingAppInfo(); } function setBrowserInfo(isMobile) { @@ -2372,7 +2368,6 @@ var AppInfo = {}; initialDependencies.push('isMobile'); initialDependencies.push('apiclient/logger'); initialDependencies.push('apiclient/store'); - initialDependencies.push('apiclient/device'); initialDependencies.push('scripts/extensions'); var supportsNativeWebComponents = 'registerElement' in document && 'content' in document.createElement('template'); @@ -2395,11 +2390,10 @@ var AppInfo = {}; link.rel = 'import'; link.onload = function () { - if (Dashboard.isRunningInCordova()) { - initCordova(resolve); - } else { - init(resolve, Dashboard.capabilities()); - } + + getHostingAppInfo().then(function (hostingAppInfo) { + init(resolve, hostingAppInfo); + }); }; link.href = "vulcanize-out.html?v=" + window.dashboardVersion; document.head.appendChild(link);