Skip to content
This repository has been archived by the owner on Apr 10, 2023. It is now read-only.

Commit

Permalink
adding auto update support
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshpa committed Nov 2, 2020
1 parent c6ff769 commit ea34eae
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 66 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main/electron-builder.yml
1 change: 1 addition & 0 deletions main/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist
electron-builder.yml
.env
**/.env
6 changes: 3 additions & 3 deletions main/app/Dbmgmt.js

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions main/app/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main/app/windows/forms.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon.ico><title>form</title><link rel=stylesheet href=./resources/roboto/css.css><link rel=stylesheet href=./resources/common.css><link href=css/chunk-vendors.3cc525fa.css rel=preload as=style><link href=js/chunk-vendors.23395ae0.js rel=preload as=script><link href=js/form.b4808b20.js rel=preload as=script><link href=css/chunk-vendors.3cc525fa.css rel=stylesheet></head><body><noscript><strong>We're sorry but form doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.23395ae0.js></script><script src=js/form.b4808b20.js></script></body></html>
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon.ico><title>form</title><link rel=stylesheet href=./resources/roboto/css.css><link rel=stylesheet href=./resources/common.css><link href=css/chunk-vendors.3d84c199.css rel=preload as=style><link href=js/chunk-vendors.23395ae0.js rel=preload as=script><link href=js/form.b4808b20.js rel=preload as=script><link href=css/chunk-vendors.3d84c199.css rel=stylesheet></head><body><noscript><strong>We're sorry but form doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.23395ae0.js></script><script src=js/form.b4808b20.js></script></body></html>
2 changes: 1 addition & 1 deletion main/app/windows/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon.ico><title>Chit Management System</title><link rel=stylesheet href=./resources/roboto/css.css><link rel=stylesheet href=./resources/common.css><link href=css/chunk-vendors.3cc525fa.css rel=preload as=style><link href=css/index.7b5cac1b.css rel=preload as=style><link href=js/chunk-vendors.23395ae0.js rel=preload as=script><link href=js/index.c8da0e90.js rel=preload as=script><link href=css/chunk-vendors.3cc525fa.css rel=stylesheet><link href=css/index.7b5cac1b.css rel=stylesheet></head><body><noscript><strong>We're sorry but Chit Management System doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.23395ae0.js></script><script src=js/index.c8da0e90.js></script></body></html>
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=favicon.ico><title>Chit Management System</title><link rel=stylesheet href=./resources/roboto/css.css><link rel=stylesheet href=./resources/common.css><link href=css/chunk-vendors.3d84c199.css rel=preload as=style><link href=css/index.7b5cac1b.css rel=preload as=style><link href=js/chunk-vendors.23395ae0.js rel=preload as=script><link href=js/index.c8da0e90.js rel=preload as=script><link href=css/chunk-vendors.3d84c199.css rel=stylesheet><link href=css/index.7b5cac1b.css rel=stylesheet></head><body><noscript><strong>We're sorry but Chit Management System doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=js/chunk-vendors.23395ae0.js></script><script src=js/index.c8da0e90.js></script></body></html>
186 changes: 138 additions & 48 deletions main/package-lock.json

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"main": "app/main.js",
"scripts": {
"test": "electron .",
"pack": "electron-builder --dir",
"dist": "electron-builder"
"pack": "electron-builder --dir --publish never",
"dist": "electron-builder --publish never",
"deploy": "electron-builder build --win --publish always"
},
"repository": {
"type": "git",
Expand All @@ -26,18 +27,19 @@
"@types/lodash": "^4.14.162",
"@types/node": "^14.11.10",
"@types/sqlite3": "^3.1.6",
"electron-builder": "^22.9.1",
"electron": "^10.1.3"
"electron": "^10.1.5",
"electron-builder": "^22.9.1"
},
"dependencies": {
"dotenv": "^8.2.0",
"electron-updater": "^4.3.5",
"lodash": "^4.17.20",
"sqlite3": "^5.0.0"
},
"build": {
"appId": "your.id",
"appId": "com.electron.chit",
"mac": {
"category": "your.app.category.type"
"category": "com.electron.chit"
},
"nsis": {
"oneClick": false,
Expand All @@ -47,8 +49,8 @@
"msi": {
"oneClick": false
},
"linux":{
"target":"AppImage"
"linux": {
"target": "AppImage"
},
"directories": {
"buildResources": "resources"
Expand Down
4 changes: 2 additions & 2 deletions main/src/Dbmgmt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class Dbmgmt {
console.log("Created new database");
}
async closeDB() {
console.log("Closing database connections");
if (this.db.db) await this.db.close();
console.log("Database connections closed");
}
async checkPhone(phone: string) {
let sql = await readFileP(join(__dirname, "./checkPhone.sql"));
let sql = await readFileP(join(__dirname, "./sql/checkPhone.sql"));
let result = await this.db.get(sql.toString(), { $phone: phone });
if (result.phone === phone) return true;
return false;
Expand Down
1 change: 1 addition & 0 deletions main/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ console.log(
let config: Configuration;
let configPath: string;
const isDevelopement: boolean = process.env.NODE_ENV ? (process.env.NODE_ENV.toLowerCase() !== 'production' && process.env.NODE_ENV.toLowerCase() === 'developement') : false;
process.env.NODE_ENV = isDevelopement?"developement":"production";
if (isDevelopement) {
configPath = process.env.CONFIGURATION_FILE;
} else {
Expand Down
19 changes: 18 additions & 1 deletion main/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ process.on('unhandledRejection', (reason, p) => {
console.log("Loading configurations and environment variables . . .");
import config from "./config";

console.log("checking for updates . . .");
import { autoUpdater } from "electron-updater";
if(process.env.NODE_ENV === "production"){
autoUpdater.on("update-downloaded", function(){
dialog.showMessageBoxSync({message:"An update is downloaded.\nThe app will restart in 10 seconds."});
setTimeout(function(){
autoUpdater.quitAndInstall();
}, 10000)
});
autoUpdater.on("update-available", function(){
if(dialog.showMessageBoxSync({message:"Do you want to download the update", buttons:["Yes", "No"]}) === 0){
autoUpdater.downloadUpdate();
}
})
autoUpdater.checkForUpdates();
}

console.log("Starting Electron . . . ");
import { BrowserWindow, app, ipcMain, nativeTheme, dialog } from "electron";
import { join } from "path";
Expand Down Expand Up @@ -166,7 +183,7 @@ app.on("before-quit", async function (ev) {
}
if (isAppQuitting) return;
isAppQuitting = true;
console.log("Closing database connection . . .");
console.log("Closing database connections . . .");
try {
await dbmgmt.closeDB();
} catch (e) {
Expand Down

0 comments on commit ea34eae

Please sign in to comment.