@exezt-/webamp 1.5.0-0x3 → 1.5.0-0x5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10084,8 +10084,18 @@ function selectAll() {
10084
10084
 
10085
10085
  class webamp_telegram_WinampTelegramCustomHandler {
10086
10086
  constructor() {
10087
+ defineProperty_default()(this, "webamp", void 0);
10088
+
10089
+ defineProperty_default()(this, "telegram", void 0);
10090
+
10091
+ defineProperty_default()(this, "initializeTelegramWebAppEvents", () => {
10092
+ this.telegram.offEvent("deactivated", () => {
10093
+ this.updateAppState();
10094
+ });
10095
+ });
10096
+
10087
10097
  defineProperty_default()(this, "updateAppState", () => {
10088
- localStorage.setItem('app-state', JSON.stringify(window.__webamp.store.getState()));
10098
+ localStorage.setItem("app-state", JSON.stringify(window.__webamp.store.getState()));
10089
10099
  });
10090
10100
 
10091
10101
  defineProperty_default()(this, "getFiles", async ln => {
@@ -10100,15 +10110,25 @@ class webamp_telegram_WinampTelegramCustomHandler {
10100
10110
  if (x.status === 200) {
10101
10111
  var _JSON$parse;
10102
10112
 
10103
- const playlistName = JSON.parse(x.responseText).name;
10104
10113
  const data = (_JSON$parse = JSON.parse(x.responseText)) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse._embedded.items;
10105
10114
  let i = 0;
10106
10115
  this.saveLastPlaylist(ln);
10107
10116
 
10108
10117
  for (const item of data) {
10109
- if (item.size > 0x1400000) {// size too large
10118
+ if (item.size > 0x1400000) {
10119
+ console.info(`File ${item.name} can't be loaded due oversize`);
10110
10120
  } else {
10111
- await fetch(item.file).then(resp => fetch(resp.url)).then(res => {
10121
+ await fetch(item.file, {
10122
+ headers: [['Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'], ['Content-Type', 'application/octet-stream']]
10123
+ }).then(response => response).then(resp => fetch(resp.url)).then(async response => {
10124
+ if (response.status === 302) {
10125
+ return await fetch(response.headers.get('Location'), {
10126
+ headers: [['Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'], ['Content-Type', 'application/octet-stream']]
10127
+ });
10128
+ } else {
10129
+ return response;
10130
+ }
10131
+ }).then(res => {
10112
10132
  var _res$body;
10113
10133
 
10114
10134
  console.log(res);
@@ -10157,6 +10177,10 @@ class webamp_telegram_WinampTelegramCustomHandler {
10157
10177
  };
10158
10178
  });
10159
10179
 
10180
+ defineProperty_default()(this, "saveLastPlaylist", playlistLink => {
10181
+ document.cookie = `lastlist=${playlistLink}; path=/;`;
10182
+ });
10183
+
10160
10184
  defineProperty_default()(this, "getCookie", name => {
10161
10185
  const regex = new RegExp(`(^| )${name}=([^;]+)`);
10162
10186
  const match = document.cookie.match(regex);
@@ -10210,44 +10234,58 @@ class webamp_telegram_WinampTelegramCustomHandler {
10210
10234
  i++;
10211
10235
  }
10212
10236
 
10213
- if (window.__webamp.store.getState().media.shuffle !== opts.media.shuffle) window.__webamp.store.dispatch({
10214
- type: "TOGGLE_SHUFFLE"
10215
- });
10216
- if (window.__webamp.store.getState().media.repeat !== opts.media.repeat) window.__webamp.store.dispatch({
10217
- type: "TOGGLE_REPEAT"
10218
- });
10237
+ if (window.__webamp.store.getState().media.shuffle !== opts.media.shuffle) {
10238
+ window.__webamp.store.dispatch({
10239
+ type: "TOGGLE_SHUFFLE"
10240
+ });
10241
+ }
10242
+
10243
+ if (window.__webamp.store.getState().media.repeat !== opts.media.repeat) {
10244
+ window.__webamp.store.dispatch({
10245
+ type: "TOGGLE_REPEAT"
10246
+ });
10247
+ }
10219
10248
  });
10220
10249
 
10221
- let lastList = this.getCookie('lastlist');
10250
+ const lastList = this.getCookie('lastlist');
10222
10251
 
10223
10252
  if (typeof lastList !== "undefined") {
10224
- this.getFiles(lastList).catch(err => 0x0);
10253
+ this.getFiles(lastList);
10225
10254
  }
10255
+ }
10226
10256
 
10227
- setTimeout(() => {
10228
- if (typeof localStorage.getItem('app-state') !== "undefined") this.loadOptions(JSON.parse(localStorage.getItem('app-state')));
10257
+ initialize() {
10258
+ var _window, _window$Telegram, _window2, _window2$Telegram;
10229
10259
 
10230
- window.__webamp.onTrackDidChange(() => {
10231
- this.updateAppState();
10232
- });
10260
+ // @ts-ignore | because no global var telegram avail in project types
10261
+ this.telegram = (_window = window) === null || _window === void 0 ? void 0 : (_window$Telegram = _window.Telegram) === null || _window$Telegram === void 0 ? void 0 : _window$Telegram.WebApp;
10233
10262
 
10234
- window.__webamp.onWillClose(() => {
10235
- this.updateAppState();
10236
- });
10263
+ if (!window.__webamp) {
10264
+ throw new Error("Webamp __webamp is undefined!!");
10265
+ } // @ts-ignore | because no global var telegram avail in project types
10237
10266
 
10238
- window.__webamp.store.dispatch({
10239
- type: "ENABLE_MILKDROP",
10240
- open: false
10241
- });
10242
- }, 2000);
10243
- }
10244
10267
 
10245
- saveLastPlaylist(playlistName) {
10246
- document.cookie = `lastlist=${playlistName}; path=/;`;
10268
+ if (!((_window2 = window) !== null && _window2 !== void 0 && (_window2$Telegram = _window2.Telegram) !== null && _window2$Telegram !== void 0 && _window2$Telegram.WebApp)) {
10269
+ console.error("Telegram is undefined!! Skipping Telegram.WebApp event handler...");
10270
+ }
10271
+
10272
+ if (typeof localStorage.getItem('app-state') !== "undefined") this.loadOptions(JSON.parse(localStorage.getItem('app-state')));
10273
+
10274
+ window.__webamp.onTrackDidChange(() => {
10275
+ this.updateAppState();
10276
+ });
10277
+
10278
+ window.__webamp.onWillClose(() => {
10279
+ this.updateAppState();
10280
+ });
10281
+
10282
+ window.__webamp.store.dispatch({
10283
+ type: "ENABLE_MILKDROP",
10284
+ open: false
10285
+ });
10247
10286
  }
10248
10287
 
10249
10288
  }
10250
- new webamp_telegram_WinampTelegramCustomHandler();
10251
10289
  // CONCATENATED MODULE: ./js/actionCreators/files.ts
10252
10290
 
10253
10291