electron 有没有办法设置电子构建器自动更新程序来检查谷歌云存储的更新?

6tr1vspr  于 2023-01-15  发布在  Electron
关注(0)|答案(2)|浏览(198)

我想使用electron-builder的autoUpdater来更新我的应用程序。我没有使用Github发行版,因为我有一个私人仓库,出于安全考虑,我不想包含GH_TOKEN。相反,我想把二进制文件和最新的.yml/latest-mac.yml文件放入Google存储桶。
我知道可以使用一个通用的提供程序来检查更新,但是目前,我甚至不能让electron-builder阅读最新的. yml,我已经花了很多时间研究文档和其他github/堆栈溢出问题,但没有找到任何解决这个问题的方法。
下面是我的main.js中的代码,用于电子/自动更新程序设置新的提要URL -

const data = {
  provider: 'generic',
  url: 'https://storage.cloud.google.com/my-project', //'my-project' is the name of the bucket
  channel: 'latest',
};
autoUpdater.setFeedURL(data);
autoUpdater.autoDownload = false;
autoUpdater.checkForUpdates();

构建的应用程序加上YML文件都在那个桶里。当我试图运行我的应用程序时,我得到了一个巨大的错误,基本上只是复制了谷歌云存储HTML/CSS,而不是阅读和处理最新的.YML文件...

Error: Error: Cannot parse update info from latest-mac.yml in the latest release artifacts (https://storage.cloud.google.com/my-project/latest-mac.yml?noCache=1dh4pdr5e): YAMLException: end of the stream or a document separator is expected at line 11, column 14:
       font-family: 'Open Sans';
                  ^
     at generateError (/Users/somelocation/documents/some-project/node_modules/js-yaml/lib/js-yaml/loader.js:167:10)
     at throwError (/Users/somelocation/documents/some-project/node_modules/js-yaml/lib/js-yaml/loader.js:173:9)
     at readDocument (/Users/somelocation/documents/some-project/node_modules/js-yaml/lib/js-yaml/loader.js:1539:5)
     at loadDocuments (/Users/somelocation/documents/some-project/node_modules/js-yaml/lib/js-yaml/loader.js:1575:5)
     at load (/Users/somelocation/documents/some-project/node_modules/js-yaml/lib/js-yaml/loader.js:1596:19)
     at safeLoad (/Users/somelocation/documents/some-project/node_modules/js-yaml/lib/js-yaml/loader.js:1618:10)
     at parseUpdateInfo (/Users/somelocation/documents/some-project/node_modules/electron-updater/out/providers/Provider.js:131:37)
     at GenericProvider.getLatestVersion (/Users/somelocation/documents/some-project/node_modules/electron-updater/out/providers/GenericProvider.js:57:48)
     at processTicksAndRejections (internal/process/task_queues.js:86:5)
     at async MacUpdater.getUpdateInfoAndProvider (/Users/somelocation/documents/some-project/node_modules/electron-updater/out/AppUpdater.js:488:13), rawData:
 <!DOCTYPE html>
 <html lang="en">
   <head>
   <meta charset="utf-8">
   <meta content="width=300, initial-scale=1" name="viewport">
   <meta name="google-site-verification" content="LrdTUW9psUAMbh4Ia074-BPEVmcpBxF6Gwf0MSgQXZs">
   <title>Sign in - Google Accounts</title>

是否有可能从Google云存储桶而不是S3或Github读取文件?另外,我已经尝试过从yml文件中删除多余的行或制表符。

slwdgvem

slwdgvem1#

您应该使用GCP API而不是浏览器URL。
这段代码对我很有效:

"publish": {
   "provider": "generic",
   "url": "https://storage.googleapis.com/YOUR_BUCKET/"
}

也可以使用https://cloud.google.com/storage/docs/json_api/v1,但它需要OAuth

4szc88ey

4szc88ey2#

尝试在应用程序“就绪”事件后执行此代码。

app.on('ready', () => {
    const feedURL = 'https://storage.cloud.google.com/my-project';
    autoUpdater.setFeedURL(feedURL); 
    autoUpdater.checkForUpdates(); 
});

相关问题