This repository has been archived by the owner on Jan 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
297 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import Store from 'electron-store' | ||
import axios from 'axios' | ||
import { API_URI } from '../renderer/config' | ||
|
||
const { dialog } = require('electron') | ||
const { autoUpdater } = require('electron-updater') | ||
const log = require('electron-log') | ||
const PRODUCT_TYPE = 'Ride Receipts Basic' | ||
|
||
const store = new Store() | ||
|
||
let updater | ||
autoUpdater.autoDownload = false | ||
|
||
autoUpdater.on('error', (error) => { | ||
dialog.showErrorBox('Error: ', error == null ? 'Oops something went wrong.' : (error.stack || error).toString()) | ||
}) | ||
|
||
autoUpdater.on('update-available', () => { | ||
dialog.showMessageBox({ | ||
type: 'info', | ||
title: 'Found Updates', | ||
message: 'Found updates, do you want update now? ✅', | ||
buttons: ['Sure', 'No'] | ||
}, (buttonIndex) => { | ||
if (buttonIndex === 0) { | ||
autoUpdater.downloadUpdate() | ||
} else { | ||
updater.enabled = true | ||
updater = null | ||
} | ||
}) | ||
}) | ||
|
||
autoUpdater.on('update-not-available', () => { | ||
if (typeof updater !== 'undefined') { | ||
dialog.showMessageBox({ | ||
title: 'No Updates', | ||
message: 'Current version is up-to-date. 🎉' | ||
}) | ||
updater.enabled = true | ||
updater = null | ||
} | ||
log.info('Current version is up-to-date. 🎉') | ||
}) | ||
|
||
autoUpdater.on('update-downloaded', () => { | ||
dialog.showMessageBox({ | ||
title: 'Install Updates', | ||
message: 'Updates downloaded, application will be quit for update...' | ||
}, () => { | ||
setImmediate(() => autoUpdater.quitAndInstall()) | ||
}) | ||
}) | ||
|
||
export const autoUpdateApp = () => { | ||
const licensekey = store.get('license_key') | ||
axios.post(`${API_URI}/license/verify`, { license_key: licensekey, product_type: PRODUCT_TYPE }).then((res) => { | ||
const expired = res.data.data.expired | ||
if (!expired) { | ||
autoUpdater.checkForUpdates() | ||
} else { | ||
dialog.showMessageBox({ | ||
title: 'No Updates', | ||
message: 'Your license key is expired. Please renew license key by repurchasing it from https://ridereceipts.io. ❌' | ||
}) | ||
} | ||
}).catch((err) => { | ||
if (err) { | ||
log.error(err) | ||
log.info('No license found in database') | ||
} | ||
}) | ||
} | ||
|
||
// export this to MenuItem click callback | ||
export const checkForUpdates = (menuItem, focusedWindow, event) => { | ||
updater = menuItem | ||
updater.enabled = false | ||
const licensekey = store.get('license_key') | ||
axios.post(`${API_URI}/license/verify`, { license_key: licensekey, product_type: PRODUCT_TYPE }).then((res) => { | ||
const expired = res.data.data.expired | ||
if (!expired) { | ||
autoUpdater.checkForUpdates() | ||
} else { | ||
dialog.showMessageBox({ | ||
title: 'No Updates', | ||
message: 'Your license key is expired. Please renew license key by repurchasing it from https://ridereceipts.io. ❌' | ||
}) | ||
} | ||
}).catch((err) => { | ||
if (err) { | ||
log.error(err) | ||
dialog.showMessageBox({ | ||
title: 'No Updates', | ||
message: 'License key not found in our database. ☹' | ||
}) | ||
updater.enabled = true | ||
} | ||
}) | ||
} |
Oops, something went wrong.