Files
discord-decomp/sources/modules/spotify/SpotifyUtils.tsx
T
2026-07-27 16:20:00 +03:00

342 lines
14 KiB
TypeScript

/* Metro module 10217; source: modules/spotify/SpotifyUtils.tsx; dependencies: [5, 4266, 6870, 6867, 6868, 661, 672, 4915, 6869, 10218, 2] */
function _fun79476(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#79476, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:6, offset: 0x01e54e7c, size: 369 bytes, params: 8, frame: 19
const env0_0 = require;
const _arrayLikeToArray_79479 = function(a0, a1) {
var r0;
var r1;
var r2;
var value3;
var length;
var value5;
var value = undefined;
var value2 = value == null;
reducibleJoin2: while (true) {
if (value2) {
r0 = value2;
break reducibleJoin2;
}
value3 = value > a0.length;
r0 = value3;
break reducibleJoin2;
}
reducibleJoin4: while (true) {
if (r0) {
length = a0.length;
r1 = length;
break reducibleJoin4;
}
r1 = value;
break reducibleJoin4;
}
value = (0, global.Array)(r1);
var value4 = 0;
if (value4 < r1) {
r2 = value4;
reducibleLoop5: while (true) {
value[r2] = a0[r2];
value5 = typeof r2 === 'bigint' ? r2 + 1n : +r2 + 1;
if (value5 < r1) {
r2 = value5;
continue reducibleLoop5;
}
break reducibleLoop5;
}
}
return value;
};
const asString_79480 = function(a0) {
if (typeof a0 === 'string') {
return a0;
}
var Error = global.Error;
throw new Error('value is not a string');
};
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
const env0_3 = importDefault(5) /* metro dependency 5 */;
const runningGameStoreNative = importDefault(4266) /* metro dependency 4266: RunningGameStoreNative */;
const spotifyProtocolStore = importDefault(6870) /* metro dependency 6870: SpotifyProtocolStore */;
const spotifyStore = importDefault(6867) /* metro dependency 6867: SpotifyStore */;
const spotifyConstantsModule = require(6868) /* metro dependency 6868: SpotifyConstants */;
const env0_7 = spotifyConstantsModule.SPOTIFY_APP_PROTOCOL;
const env0_8 = spotifyConstantsModule.SpotifyResourceTypes;
const env0_9 = spotifyConstantsModule.getSpotifyResourceType;
const env0_10 = (require(661) /* metro dependency 661: Constants */).PlatformTypes;
const Millis = (importDefault(672) /* metro dependency 672: Durations */).Millis;
const SECOND = Millis.SECOND;
const env0_11 = 30 * SECOND;
(require(2) /* metro dependency 2 */).fileFinishedImporting('modules/spotify/SpotifyUtils.tsx');
exports.isSpotifyPlayable = isSpotifyPlayable;
exports.ensureSpotifyPlayable = ensureSpotifyPlayable;
exports.isSpotifyPremium = isSpotifyPremium;
exports.ensureSpotifyPremium = ensureSpotifyPremium;
exports.getSpotifyMetadataFromActivity = function() {
return _getSpotifyMetadataFromActivity.apply(this, arguments);
};
}
function _createForOfIteratorHelperLoose_79477(a0, a1) { // fn#79477, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:253, offset: 0x01e54fed, size: 372 bytes, params: 3, frame: 20
var r6;
var r9;
var r5;
var value3;
var regexp;
const env0_0 = a0;
const Symbol = global.Symbol;
let value = typeof Symbol !== 'undefined';
let r1 = value && a0[global.Symbol.iterator];
r1 = !r1 ? a0['@@iterator'] : r1;
if (r1) {
value = r1.call(a0);
return value.next.bind(value);
}
const Array = global.Array;
if (Array.isArray(a0)) {
if (r1) {
}
return _fun79478;
}
value = undefined;
if (a0) {
if (typeof a0 === 'string') {
value = _arrayLikeToArray_79479(a0, value);
r5 = value;
} else {
value3 = ({}).toString.call(a0).slice(8, -1);
r6 = value3 === 'Object' && a0.constructor;
r9 = r6 ? a0.constructor.name : value3;
if (r9 === 'Map') {
r6 = global.Array.from(a0);
} else if (r9 === 'Set') {
r6 = global.Array.from(a0);
} else if (r9 === 'Arguments') {
value = _arrayLikeToArray_79479(a0, value);
r6 = value;
} else {
regexp = RegExp('^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$', '');
if (regexp.test(r9)) {
value = _arrayLikeToArray_79479(a0, value);
r6 = value;
} else {
r6 = value;
}
}
r5 = r6;
}
} else {
r5 = value;
}
if (r5) {
if (r5) {
}
return _fun79478;
}
const TypeError = global.TypeError;
throw new TypeError('Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.');
}
function _getSpotifyMetadataFromActivity() { // fn#79481, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:1287, offset: 0x01e55195, size: 50 bytes, params: 1, frame: 14
return env0_3(_fun79483).apply(this, arguments);
}
function isSpotifyPlayable(a0) { // fn#79484, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:1888, offset: 0x01e5532e, size: 41 bytes, params: 2, frame: 10
let value = a0.getActiveSocketAndDevice();
value = value != null;
return value || SpotifyProtocolStore.isProtocolRegistered();
}
function ensureSpotifyPlayable() { // fn#79485, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:2012, offset: 0x01e55357, size: 342 bytes, params: 1, frame: 19
var Promise;
var playableComputerDevices;
var isObservedAppRunning;
var defaultImport;
var promise;
var property;
var socket;
var device;
var value;
const activeSocketAndDevice = SpotifyStore.getActiveSocketAndDevice();
if (activeSocketAndDevice != null) {
return global.Promise.resolve(activeSocketAndDevice);
}
if (SpotifyProtocolStore.isProtocolRegistered()) {
playableComputerDevices = SpotifyStore.getPlayableComputerDevices();
isObservedAppRunning = RunningGameStoreNative.isObservedAppRunning;
defaultImport = importDefault(4915) /* metro dependency 4915: Platforms */;
if (Reflect.apply(isObservedAppRunning, RunningGameStoreNative,
[defaultImport.get(PlatformTypes.SPOTIFY).name])) {
if (playableComputerDevices.length > 0) {
property = playableComputerDevices[0];
socket = property.socket;
device = property.device;
value = require(6869) /* metro dependency 6869: SpotifyActionCreators */;
value.setActiveDevice(socket.accountId, device.id);
Promise = global.Promise;
return Promise.resolve({socket: socket, device: device});
}
Promise = global.Promise;
value = Object.create(Promise.prototype, {constructor: {value: Promise}});
promise = new Promise(_fun79486);
return promise instanceof Object ? promise : value;
}
Promise = global.Promise;
value = Object.create(Promise.prototype, {constructor: {value: Promise}});
promise = new Promise(_fun79486);
return promise instanceof Object ? promise : value;
}
Promise = global.Promise;
const reject = Promise.reject;
const Error = global.Error;
return Reflect.apply(reject, Promise, [new Error('protocol is not registered')]);
}
function isSpotifyPremium() { // fn#79492, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:3034, offset: 0x01e556b0, size: 40 bytes, params: 1, frame: 10
const activeSocketAndDevice = SpotifyStore.getActiveSocketAndDevice();
const value2 = null;
return value2 == activeSocketAndDevice ? value2 : activeSocketAndDevice.socket.isPremium;
}
function ensureSpotifyPremium() { // fn#79493, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:3161, offset: 0x01e556d8, size: 181 bytes, params: 1, frame: 14
var r0;
var Promise;
var value;
const activeSocketAndDevice = SpotifyStore.getActiveSocketAndDevice();
if (activeSocketAndDevice == null) {
Promise = global.Promise;
return Promise.reject(new global.Error('no active profile'));
}
const socket = activeSocketAndDevice.socket;
if (socket.isPremium) {
r0 = global.Promise.resolve();
} else {
value = require(6869) /* metro dependency 6869: SpotifyActionCreators */;
value = value.getProfile(socket.accountId, socket.accessToken);
value = value.then(_fun79494);
r0 = value;
}
return r0;
}
function* _fun79483(a0, a1) { // fn#79483, original name: ?anon_0_, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:1372, offset: 0x01e551d2, size: 348 bytes, params: 3, frame: 19
if (false) {
return undefined;
}
value = environment.__proto__.__proto__;
let binding = env2_0;
const value3 = undefined;
const value4 = binding(env2_2[9]);
const getMetadata = value4.getMetadata;
yield Reflect.apply(getMetadata, value4, [a0, a1]);
const value5 = undefined;
if (false) {
return value5;
}
binding = env2_9;
const binding2 = env2_14;
const r3 = value5.type ?? env2_8.TRACK;
binding2(r3);
const value7 = binding(r3);
if (value7 === null) {
throw new global.Error('invalid type ' + value5.type);
}
const object2 = {};
let context_uri = value5.context_uri;
context_uri = typeof context_uri !== 'string' ? value3 : value5.context_uri;
object2.context_uri = context_uri;
binding = env2_14;
const album_id = value5.album_id;
binding(album_id);
object2.album_id = album_id;
let Array = global.Array;
object2.artist_ids = Array.isArray(value5.artist_ids) ? value5.artist_ids.map(env2_14) : [];
object2.type = value7;
Array = global.Array;
object2.button_urls = Array.isArray(value5.button_urls) ? value5.button_urls.map(env2_14) : [];
return object2;
}
function _fun79486(a0, a1) { // fn#79486, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:2454, offset: 0x01e554ad, size: 124 bytes, params: 3, frame: 16
const env0_0 = a0;
const env0_1 = a1;
const env0_2 = global.setTimeout(_fun79487, env1_11);
SpotifyStore.addChangeListener(onSpotifyStoreChange);
global.window.open('' + SPOTIFY_APP_PROTOCOL + ':');
}
function _fun79494() { // fn#79494, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:3398, offset: 0x01e5578d, size: 73 bytes, params: 1, frame: 13
if (socket.isPremium) {
return undefined;
}
const Promise = global.Promise;
const reject = Promise.reject;
const Error = global.Error;
return Reflect.apply(reject, Promise, [new Error('spotify account is not premium')]);
}
function _fun79487() { // fn#79487, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:2480, offset: 0x01e55529, size: 72 bytes, params: 1, frame: 12
const value = environment.__proto__.__proto__;
SpotifyStore.removeChangeListener(onSpotifyStoreChange);
const Error = global.Error;
require(new Error('timeout launching spotify'));
}
function onSpotifyStoreChange() { // fn#79488, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:2598, offset: 0x01e55571, size: 89 bytes, params: 1, frame: 15
var environment;
var r2;
var value3;
var socket;
var device;
var value4;
const closure = onSpotifyStoreChange_loop;
let value = environment.__proto__.__proto__;
const _createForOfIteratorHelperLoose_79477Binding = _createForOfIteratorHelperLoose_79477;
value = SpotifyStore.getPlayableComputerDevices();
value = _createForOfIteratorHelperLoose_79477Binding(value);
const value2 = value();
let done = value2.done;
if (!done) {
for (r2 = value2; true; r2 = value4) {
value3 = r2.value;
socket = value3.socket;
device = value3.device;
closure(socket, device);
value4 = value();
done = value4.done;
if (done) {
break;
}
}
}
}
function onSpotifyStoreChange_loop(a0, a1) { // fn#79489, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:2619, owner: onSpotifyStoreChange._loop, offset: 0x01e555ca, size: 113 bytes, params: 3, frame: 14
var environment;
var clearTimeout;
var value2;
const env0_0 = a0;
const env0_1 = a1;
let value = environment.__proto__.__proto__;
value = env2_0.find(function(a0) {
return a0.device.id === require.id;
});
if (value == null) {
clearTimeout = global.clearTimeout;
value = environment.__proto__;
clearTimeout(env1_2);
value2 = environment.__proto__.__proto__.__proto__;
SpotifyStore.removeChangeListener(onSpotifyStoreChange);
global.setImmediate(_fun79491);
}
}
function _fun79491() { // fn#79491, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:10403:2748, offset: 0x01e5565b, size: 85 bytes, params: 1, frame: 16
let value = environment.__proto__.__proto__.__proto__.__proto__;
value = require(6869) /* metro dependency 6869: SpotifyActionCreators */;
const setActiveDevice = value.setActiveDevice;
const binding = env0_0;
Reflect.apply(setActiveDevice, value, [binding.accountId, require.id]);
value = environment.__proto__.__proto__;
env2_0({socket: binding, device: require});
}