Skip to content

Commit 7ff0979

Browse files
committed
fix problem with updating
1 parent e1a25ba commit 7ff0979

File tree

9 files changed

+176
-167
lines changed

9 files changed

+176
-167
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# electron_learn
2+
3+
Welcome to `electron_learn`! This repository contains code examples and resources to help you learn how to build desktop applications with Electron.
4+
5+
## What is Electron?
6+
7+
Electron is an open-source framework for building cross-platform desktop applications using web technologies such as HTML, CSS, and JavaScript. It was created by GitHub and has been used to build applications such as Atom, Slack, and Visual Studio Code.
8+
9+
## Getting Started
10+
11+
To get started with Electron, you'll need to have Node.js and npm (Node Package Manager) installed on your computer. Once you have those installed, you can clone this repository and run the following commands:
12+
13+
```
14+
npm i
15+
npm run start
16+
```
17+
18+
This will install the necessary dependencies and start the Electron app.
19+
20+
To get started with developer mode:
21+
22+
```
23+
npm run dev
24+
```
25+
26+
## Releases
27+
28+
This repository includes [releases](https://github.com/semklim/electron_learn/releases) that you can download and run on your computer. Each release includes a pre-built version of the app for macOS, Windows, and Linux.
29+
30+
## Updating the App
31+
32+
The app includes an auto-updating feature that uses [electron-builder](https://www.electron.build/) to package and distribute updates. When a new release is available, the app will automatically download and install it.
33+
34+
## Resources
35+
36+
Here are some resources to help you learn more about Electron:
37+
38+
- [Electron documentation](https://www.electronjs.org/docs)
39+
- [Electron API Demos](https://github.com/electron/electron-api-demos)
40+
- [Electron-builder](https://www.electron.build/)
41+
- [Awesome Electron](https://github.com/sindresorhus/awesome-electron)
42+
43+
Happy learning!

client/Create.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
position: absolute;
3434
top: 20%;
3535
width: 100%;
36+
display: flex;
37+
justify-content: space-evenly;
38+
align-items: center;
3639
}
37-
3840
</style>
3941
</head>
4042
<body>

client/Script.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
const { ipcRenderer } = require(`electron`);
22
const updateInfo = document.getElementById('updateInfo');
3+
34
add.addEventListener('click', () => ipcRenderer.send('createNewWindow'));
45
updateInfo.textContent = "";
5-
ipcRenderer.on('update', (event, ...arg) => {
6-
updateInfo.textContent = arg;
7-
console.log(arg);
6+
ipcRenderer.on('update', (event, arg) => {
7+
console.log(arg);
8+
if (typeof arg === 'string') {
9+
updateInfo.textContent = arg;
10+
return;
11+
}
12+
const rest = arg[1] && arg[1].version ? arg[1].version : '';
13+
updateInfo.textContent = arg[0] + ' ' + rest;
14+
});
15+
16+
ipcRenderer.on('update-color-signal', (event, arg) => {
17+
const rest = arg[1] ? arg[1].version : '';
18+
updateInfo.textContent = arg[0] + ' ' + rest;
819
});
920

1021
ipcRenderer.on('ver', (event, arg) => {
11-
versionInfo.textContent = 'Version ' + arg;
12-
console.log(arg);
22+
versionInfo.textContent = 'Version ' + arg;
23+
console.log(arg);
1324
});

defaultWindow.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
const { BrowserWindow } = require("electron");
22

33
function createWindow ({ loadFile, positionX, positionY, width, height }) {
4-
const win = new BrowserWindow({
5-
width: (width || 300),
6-
height: (height || 200),
7-
show: false,
8-
webPreferences: {
9-
// node packages is available in index.html
10-
nodeIntegration: true,
11-
contextIsolation: false,
12-
},
13-
autoHideMenuBar: true,
14-
frame: false,
15-
// resizable: false,
16-
alwaysOnTop: true
17-
});
18-
if (typeof loadFile === 'string') {
19-
win.loadFile(loadFile);
20-
}
21-
if (positionX && positionY) {
22-
win.setBounds({ x: positionX, y: positionY });
23-
}
24-
return win;
4+
const win = new BrowserWindow({
5+
width: (width || 450),
6+
height: (height || 300),
7+
show: false,
8+
webPreferences: {
9+
// node packages is available in index.html
10+
nodeIntegration: true,
11+
contextIsolation: false,
12+
},
13+
autoHideMenuBar: true,
14+
frame: false,
15+
// resizable: false,
16+
alwaysOnTop: true
17+
});
18+
if (typeof loadFile === 'string') {
19+
win.loadFile(loadFile);
20+
}
21+
if (positionX && positionY) {
22+
win.setBounds({ x: positionX, y: positionY });
23+
}
24+
return win;
2525
};
2626

2727
module.exports = { createWindow };

index.js

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,63 +2,63 @@ const { app } = require('electron');
22
const ipcMain = require('./IpcMain/ipcMainEvents');
33
const { createWindow } = require('./defaultWindow');
44
const { createTray } = require('./Tray/tray');
5-
const { autoUpdater } = require('electron-updater');
5+
const { autoUpdater, AppUpdater } = require('electron-updater');
66
let mainWin;
77

88
autoUpdater.autoDownload = false;
99
autoUpdater.autoInstallOnAppQuit = true;
1010

11-
autoUpdater.on('update-available', () => {
12-
autoUpdater.downloadUpdate();
13-
});
11+
const showMSGGUI = (chanel, ...msg) => {
12+
mainWin.webContents.send(chanel, msg);
13+
};
1414

15-
autoUpdater.on('update-downloaded', () => {
16-
autoUpdater.quitAndInstall();
17-
});
15+
app.whenReady().then(() => {
16+
setUpdaterListeners();
17+
mainWin = createWindow({
18+
loadFile: './client/Create.html',
19+
positionX: 950,
20+
positionY: 100,
21+
});
1822

23+
mainWin.show();
24+
mainWin.webContents.send('update', 'Checking for update');
25+
mainWin.webContents.send('ver', app.getVersion());
26+
autoUpdater.checkForUpdates();
1927

20-
app.whenReady().then(() => {
21-
setUpdaterListeners();
22-
mainWin = createWindow({
23-
loadFile: './client/Create.html',
24-
positionX: 950,
25-
positionY: 200,
26-
});
27-
mainWin.show();
28-
mainWin.webContents.send('update', 'Checking for update'); //Раз передає повідомлення, раз не передає. Не можу знайти причину такої поведінки. Підскажіть, що я не так роблю.
29-
mainWin.webContents.send('ver', app.getVersion());
30-
autoUpdater.checkForUpdates();
3128

32-
createWindow({
33-
loadFile: './client/Move.html',
34-
positionX: 950,
35-
positionY: 500,
36-
}).show();
29+
createWindow({
30+
loadFile: './client/Move.html',
31+
positionX: 950,
32+
positionY: 500,
33+
}).show();
3734
});
3835

3936

4037
app.on('window-all-closed', () => {
41-
if (process.platform !== 'darwin') {
42-
app.quit();
43-
}
38+
if (process.platform !== 'darwin') {
39+
app.quit();
40+
}
4441
});
4542

4643

47-
const sendMsg = (chanel, ...msg) => {
48-
mainWin.webContents.send(chanel, msg);
49-
};
44+
const setUpdaterListeners = () => {
45+
autoUpdater.on('update-available', (info) => {
46+
showMSGGUI('update-color-signal', 'update-available', info);
47+
autoUpdater.downloadUpdate();
48+
});
49+
50+
autoUpdater.on('update-not-available', (info) => {
51+
showMSGGUI('update', 'It`s latest version');
52+
});
53+
54+
autoUpdater.on('update-downloaded', (info) => {
55+
const newVers = info.version;
56+
showMSGGUI('update', 'update-downloaded', info);
57+
58+
setTimeout(() => { showMSGGUI('update', `Please restart app for updating to version ${newVers}`); }, 3000);
59+
});
5060

51-
function setUpdaterListeners () {
52-
autoUpdater.on('update-available', (info) => {
53-
sendMsg('update', 'update-available', info);
54-
});
55-
autoUpdater.on('update-not-available', (info) => {
56-
sendMsg('update', 'update-not-available', info);
57-
});
58-
autoUpdater.on('update-downloaded', (info) => {
59-
sendMsg('update', 'update-downloaded', info);
60-
});
61-
autoUpdater.on('error', (info) => {
62-
sendMsg('update', 'error', info);
63-
});
61+
autoUpdater.on('error', (info) => {
62+
showMSGGUI('update', 'error', info);
63+
});
6464
};

license.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

package-lock.json

Lines changed: 28 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)