nondanee / vsc-netease-music

UNOFFICIAL Netease Music extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=nondanee.vsc-netease-music
MIT License
1.02k stars 79 forks source link

是否支持Insiders版? #50

Closed RoyLi-Pvt closed 5 years ago

RoyLi-Pvt commented 5 years ago

Version: 1.36.0-insider (user setup) Commit: 9ff8ae037e8e6109d65e4b5e3eb3dc60cc187e21 Date: 2019-06-21T07:52:00.716Z Electron: 4.2.4 Chrome: 69.0.3497.128 Node.js: 10.11.0 V8: 6.9.427.31-electron.0 OS: Windows_NT x64 10.0.18362

播放没有声音 Console报错有两条

[Embedded Page] NotAllowedError webviewElement.ts:363
[Embedded Page] Uncaught (in promise) NotSupportedError: Failed to load because no supported source was found. webviewElement.ts:363

第一条是Start时出现的第二条是开始播放时出现的 Network似乎没有活动

nondanee commented 5 years ago

insider 已经用 Electron 4.x 了啊! 你替换一下 ffmpeg.dll 看看

RoyLi-Pvt commented 5 years ago

替换了一下OK了.抱歉没有先尝试替换,因为我看ReadMe说1.31之后不用替换了😀

另外我在搜索dll的路径的时候发现VSCodeLiveShareAudio似乎自带了一个ffmpeg呢,路径在 .vscode-insiders\extensions\ms-vsliveshare.vsliveshare-audio-0.1.56\node_modules\electron\dist\ffmpeg.dll

是不是也可以考虑插件自己附带ffmpeg库?

nondanee commented 5 years ago

@TMily ffmpeg 和 electron 有关 1.31 从 electron 2.x 到 3.x insider 1.36 是 4.x

这是 electron 依赖的 dll

不考虑,单独用 ffmpeg 只能解码,播放还要别的东西

你看看 .vscode\extensions\ms-vsliveshare.vsliveshare-audio-0.1.56\node_modules 这个文件夹是不是有 170m+,那应该是一个完整的 electron

RoyLi-Pvt commented 5 years ago

嗯我这边看是120M左右,只是个提案. 我只是感觉既然微软官方也用了这种方式,是不是本插件也可以用同样的方式. 或者只是支持配置一个外部electron路径也好. 这样就不用每次安装后进行替换了,Insider的更新频率即使是脚本替换也不是很完美的解决方式. 这个文件夹应该不是直接打包进扩展而是通过安装后再下载的方式获取的. 不过这些和这个Issue不太相关了,先行close了~~

nondanee commented 5 years ago

@TMily 100M+ 基本可以确定是用了完整 electron 了 对的,extension install 完成后再 npm install 的

再下载一个 electron 开销太大了,如果要用 electron-spawn 的话不如通过 puppeteer 控制已安装的 chrome 播放

因为 node 标准库不支持解压 zip,所以替换脚本是 python 而不是 node,不然的话可以直接用 extension 线程来替换 (会更方便)

而且脚本里已经换用淘宝的 electron mirror 了,下载应该还是很快的

RoyLi-Pvt commented 5 years ago

但是这个自动下载他是半持久化的能跨VSCode版本的,我个人认为开销还是可控的. VSCodeLiveShareAudio为例,大部分情况下并不会进行下载.只有刚安装完下载一次,剩下的仅有扩展本身的依赖版本变了才会下载. 感觉这比每次都要手动替换要好的多😀

RoyLi-Pvt commented 5 years ago

另外还是之前的提议,仅仅作为一个额外的配置项允许引用外部electron是否可以呢?

nondanee commented 5 years ago

@TMily 我试了下用 electron spawn 比较麻烦,为了 loadURL 还需要再加主线程 js 所以还是 puppeteer,改动会比较小

你可以

npm install puppeteer

并把这里 https://github.com/nondanee/vsc-netease-music/blob/9336b126f1e29b93094b966888c52050d32427c1/runtime.js#L269-L283 改成

const WebviewPanel = context => {
    let handle

    require('puppeteer').launch({
        ignoreDefaultArgs: ['--mute-audio'],
        args: ['--autoplay-policy=no-user-gesture-required']
    })
    .then(browser => {
        handle = browser
        return browser.pages()
    })
    .then(pages => pages[0].goto(`file://${path.join(context.extensionPath, 'index.html')}`))

    return {
        dispose: () => {
            if (handle) handle.close()
        }
    }
}

P.S. 下载的 chromium 大概有 170M 如果系统有安装 chrome 的话,可以直接用 puppeteer-core 调用 chrome

npm install puppeteer-core

并修改

require('puppeteer-core').launch({
    ignoreDefaultArgs: ['--mute-audio'],
    args: ['--autoplay-policy=no-user-gesture-required'],
    executablePath: 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe' // Windows 下默认安装位置
})
nondanee commented 5 years ago

发现 electron.exe file://index.html 可以直接启动不需要主线程 js 但是我试了下在插件里根本不能 spawn/exec 出 electron.exe,不知道为什么

nondanee commented 5 years ago

知道为什么了,是因为 ELECTRON_RUN_AS_NODE 😥

nondanee commented 5 years ago

用 electron 的话就这样

npm install puppeteer-electron
const WebviewPanel = context => {
    let handle

    require('puppeteer-electron').launch()
    .then(browser => {
        handle = browser
        return browser.pages()
    })
    .then(pages => pages[0].goto(`file://${path.join(context.extensionPath, 'index.html')}`))

    return {
        dispose: () => {
            if (handle) handle.close()
        }
    }
}
nondanee commented 5 years ago

为了支持 remote 环境,我就不考虑用外部 Electron 了嗷~ (插件运行在 server 那边,用外部 Electron 的话听不到声音)