Skip to content

Commit

Permalink
add funtctions and listeners to start.js and EntrySection.js to test …
Browse files Browse the repository at this point in the history
…autoUpdater of electron-updater. till now I was'nt successful
  • Loading branch information
devomid committed May 27, 2024
1 parent f9a4b60 commit ef120cb
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 12 deletions.
66 changes: 62 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"electron-updater": "^6.1.8",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.29.1",
Expand Down Expand Up @@ -73,15 +74,30 @@
"electron-builder": "^24.13.3",
"electron-is-dev": "^3.0.1"
},
"files": ["build", "*.js", "node_modules", "package.json","index.html", "package-lock.json"],
"files": [
"build",
"*.js",
"node_modules",
"package.json",
"index.html",
"package-lock.json"
],
"build": {
"appId": "SSP Price Checker",
"productName": "SSP Price Checker",
"extends": null,
"publish": [
{
"provider": "github",
"owner": "devomid",
"repo": "SSP-Price-Checker"
}
],
"win": {
"target": [
"nsis"
],
"icon":"./src/assets/icon/icon.ico"
"icon": "./src/assets/icon/icon.ico"
},
"directories": {
"buildResources": "resources",
Expand Down
7 changes: 5 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ const cacheRtl = createCache({
});



function App() {



return (
<CacheProvider value={cacheRtl}>

Expand Down Expand Up @@ -54,4 +55,6 @@ function App() {
)
}

export default App;
export default App;


22 changes: 20 additions & 2 deletions src/pages/EntrySection.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import 'jalaali-react-date-picker/lib/styles/index.css';
import moment from 'moment-jalaali';
import 'moment/locale/fa';
import 'moment-jalaali';
const { ipcRenderer } = window.require('electron');



const EntrySection = () => {
Expand Down Expand Up @@ -317,7 +319,7 @@ const EntrySection = () => {

const claculateKarbarEzafe = () => {
if (destCode) {
if (tamdidPrice){
if (tamdidPrice) {
if (karbarEzafe == 0 || appCodes.hasOwnProperty(destCode)) {
const karbarEzafeValue = (Number(tamdidPrice) / 10) * (Number(karbarEzafe))
setKarbarEzafePrice(karbarEzafeValue)
Expand All @@ -328,7 +330,7 @@ const EntrySection = () => {

} else {
if (karbarEzafe == 0 || appCodes.hasOwnProperty(destCode)) {

if (networkCodes.includes(destCode) || karbarEzafe == 0) {
const karbarEzafeValue = Number(((appPrices[destCode]) / 10) * karbarEzafe)
setKarbarEzafePrice(karbarEzafeValue)
Expand Down Expand Up @@ -710,6 +712,22 @@ const EntrySection = () => {
reset()
}, [resetState]);

useEffect(() => {

ipcRenderer.on('update-available', () => {
console.log('update available');
});

ipcRenderer.on('download-progress', (event, progressObj) => {
console.log(event);
console.log(progressObj);
});

ipcRenderer.on('update-downloaded', () => {
console.log('download finished');
});
}, [])


return (
<Box sx={{ maxHeight: '97%', width: '50%', backgroundColor: 'rgba(255, 255, 255, 0.5)', backdropFilter: 'blur(5px) saturate(180%)', border: '1px solid rgba(38, 66, 77, 0.5)', mt: '1rem', borderRadius: 5, boxShadow: 3, padding: '1rem' }}>
Expand Down
19 changes: 17 additions & 2 deletions src/start.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, BrowserWindow } = require('electron')
const { app, BrowserWindow, autoUpdater } = require('electron')
const { ipcMain } = require('electron')
const { protocol } = require('electron');

Expand All @@ -24,7 +24,9 @@ function createWindow() {
resizable: false
});

mainWindow.setMenuBarVisibility(false)
mainWindow.setMenuBarVisibility(false)

mainWindow.webContents.openDevTools()

mainWindow.loadURL(
process.env.ELECTRON_START_URL ||
Expand All @@ -43,6 +45,19 @@ function createWindow() {

app.on('ready', createWindow)

autoUpdater.on('update-available', () => {
mainWindow.webContents.send('update-available');
});

autoUpdater.on('download-progress', (progressObj) => {
mainWindow.webContents.send('download-progress', progressObj);
});

autoUpdater.on('update-downloaded', () => {
mainWindow.webContents.send('update-downloaded');
autoUpdater.quitAndInstall()
});

ipcMain.on('bye', () => {
app.quit()
})
Expand Down

0 comments on commit ef120cb

Please sign in to comment.