Skip to content

Commit

Permalink
publish VSIX
Browse files Browse the repository at this point in the history
  • Loading branch information
yne committed Aug 28, 2023
1 parent 3f7992e commit a3f8679
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
- name: check key extract
run: |
[ "$(DZR_CBC= ./dzr ! 2>/dev/null | sha1sum)" = '3ad58d9232a3745ad9308b0669c83b6f7e8dba4d -' ]
- name: bundle VSIX
run: zip -r $(jq -r '.name+"-"+.version+".vsix"' < extension/package.json) extension
- name: publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
18 changes: 13 additions & 5 deletions extension/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const type2icon = {
user: '$(account) ',
};
const hhmmss = (s) => (new Date(s * 1000)).toISOString().slice(11, 19).replace(/^00:/, '');
const wait = (ms=1000) => new Promise(resolve => setTimeout(resolve, ms));
// still no fetch() in 2023 ?
const fetch = (url, opt, data) => new Promise((resolve, reject) => {
const chunks = [], req = https.request(url, opt, res => {
Expand Down Expand Up @@ -90,7 +91,7 @@ async function browse(url_or_event, label) {
}
} catch (e) { console.error(e) }
}

/* songs may came from API (full info) or storage (light info) */
const with_url = async (songs) => songs?.length ? await vscode.window.withProgress({ title: 'Fetching Song Info...', location }, async (progress) => {
try {
const next = (val) => (progress.report({ increment: 100 / 4 }), val);
Expand All @@ -107,9 +108,12 @@ const with_url = async (songs) => songs?.length ? await vscode.window.withProgre
}))));
const errors = URL_NFO.data.map((nfo, i) => [nfo.errors, songs[i]]).filter(([err]) => err).map(([[err], sng]) => `${sng.title}: ${err.message} (${err.code})`).join('\n');
if (errors) setTimeout(() => vscode.window.showWarningMessage(errors), 500); // can't warn while progress ?
return songs.map(({ id, title_short, title_version, artist, contributors, duration }, i) => ({
id, title: title_short.replace(/ ?\(feat.*?\)/, ''), version: title_version, duration,
artists: (contributors || [artist])?.map(({ id, name }) => ({ id, name })),
return songs.map(({/* api :*/ id, md5_image, duration, title_short, title_version, artist, contributors,
/*cache:*/ title, version, artists }, i) => ({
id, md5_image, duration,
title: title_short?.replace(/ ?\(feat.*?\)/, '') || title,
version: title_version || version,
artists: artists??(contributors || [artist])?.map(({ id, name }) => ({ id, name })),
size: +SNG_NFO.data[i].FILESIZE,
expire: SNG_NFO.data[i].TRACK_TOKEN_EXPIRE,
url: URL_NFO.data[i].media?.[0]?.sources?.[0]?.url
Expand Down Expand Up @@ -257,7 +261,11 @@ exports.activate = async function (/**@type {vscode.ExtensionContext}*/ context)
item && vscode.commands.executeCommand('dzr.load', item);
}),
vscode.commands.registerCommand("dzr.load", async (item) => {
if (item.expire > new Date()/1000) {
if (!dzr.state.ready) {
vscode.commands.executeCommand('dzr.show');
while (!dzr.state.ready) await wait();
}
if (item.expire < (new Date()/1000)) {
with_url(dzr.state.queue);//TODO: hope item is now up to date
}
const hex = (str) => str.split('').map(c => c.charCodeAt(0))
Expand Down
2 changes: 1 addition & 1 deletion extension/webview.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1>Disclamer</h1>
let mediaSource, sourceBuffer;
const on = {// event from VSCode
async open(item) {
img.src = "https://api.deezer.com/cover/"+item.id;
img.src = `https://e-cdns-images.dzcdn.net/images/cover/${item.md5_image}/1000x1000-000000-80-0-0.jpg`;
mediaSource = new window.MediaSource();
audio.src = window.URL.createObjectURL(mediaSource);
await new Promise(then => mediaSource.onsourceopen = () => then());
Expand Down

0 comments on commit a3f8679

Please sign in to comment.