因此,我对电子编程尚不陌生,正在尝试让我的电子应用程序查看我的github版本,并确定我的本地文件是否比github存储库上的最新文件版本新/旧。目前,我目前正在使用0.0.2-alpha版本,希望看到我的按钮将状态更改为“更新就绪”,但是在我的github版本上似乎没有看到我的最新版本0.0.3-alpha。该代码已为OSX签名,并且我已设置了所有令牌信息。请参见下面的代码:
Main.js
const {app, BrowserWindow, ipcMain} = require('electron');
const {autoUpdater} = require("electron-updater");
let win; // this wills store the window object
function createDefaultWindow() {
win = new BrowserWindow({width: 900, height: 680});
win.loadURL(`file://${__dirname}/index.html`);
win.on('closed', () => app.quit());
return win;
}
// when the update is ready, notify the BrowserWindow
autoUpdater.on('update-downloaded', (info) => {
win.webContents.send('updateReady')
});
app.on('ready', function() {
createDefaultWindow();
autoUpdater.checkForUpdates();
});
ipcMain.on("quitAndInstall", (event, arg) => {
autoUpdater.quitAndInstall();
})
Index.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
<!---<script type="text/javascript" src="login.js"></script>-->
<meta charset="UTF-8">
<title>Temp Launcher 0.0.2-alpha</title>
</head>
<body>
<script>
// You can also require other files to run in this process
require('./renderer.js')
</script>
<script>
const ipcRenderer = require('electron').ipcRenderer;
// wait for an updateReady message
ipcRenderer.on('updateReady', function(event, text) {
// changes the text of the button
var container = document.getElementById('ready');
container.innerHTML = "new version ready!";
alert('update ready!');
})
</script>
<div id="content">
<h1 style="text-align:center;">Temp Launcher</h1>
<h3 style="text-align: center;">Version: <span id="version">v0.0.2-alpha</span></h3>
<br />
<br />
<!-- the button onClick sends a quitAndInstall message to the electron main process -->
<button id="ready" onClick="ipcRenderer.send('quitAndInstall')">no updates ready</button>
<div id="messages" style="color:cyan">Messages</div>
<div class="w3-light-grey">
<div class="w3-blue" style="height:24px;width:0%" id="progressBar"></div>
</div>
<div id="bottom-updater-bar">
<div id="sidenavbar">
<a href="#item1" id="sidenavbaritems">ITEM 1</a>
</div>
UPDATER
</div>
Renderer.js
const { ipcRenderer } = require('electron');
const select = selector => document.querySelector(selector)
let container = select('#messages')
let progressBar = select('#progressBar')
let version = select('#version')
ipcRenderer.on('message', (event, text) => {
let message = document.createElement('div')
message.innerHTML = text
container.appendChild(message)
})
ipcRenderer.on('version', (event, text) => {
version.innerText = text
})
ipcRenderer.on('download-progress', (event, text) => {
progressBar.style.width = `${text}%`
})
我不确定自己在做什么错,因为据我所知,这已经为他人奏效了。任何帮助表示赞赏。谢谢。