Update system

This commit is contained in:
Fabio 2020-06-19 18:03:52 +02:00
parent 0d10a93bf8
commit 42e0353393
15 changed files with 197 additions and 31 deletions

3
.gitignore vendored
View File

@ -5,4 +5,5 @@ thumbs.db
.idea/ .idea/
.vscode .vscode
TODO.md TODO.md
*.txt *.txt
dev-app-update.yml

View File

@ -1,7 +1,7 @@
{ {
"name": "antares", "name": "antares",
"productName": "Antares", "productName": "Antares",
"version": "0.0.0-alpha", "version": "0.0.1-alpha",
"description": "A cross-platform easy to use SQL client.", "description": "A cross-platform easy to use SQL client.",
"license": "MIT", "license": "MIT",
"repository": "https://github.com/Fabio286/antares.git", "repository": "https://github.com/Fabio286/antares.git",
@ -15,7 +15,7 @@
"author": "Fabio Di Stasio <fabio286@gmail.com>", "author": "Fabio Di Stasio <fabio286@gmail.com>",
"build": { "build": {
"appId": "com.estarium.antares", "appId": "com.estarium.antares",
"artifactName": "${productName}-${version}-${channel}-${os}_${arch}.${ext}", "artifactName": "${productName}-${version}-${os}_${arch}.${ext}",
"files": [ "files": [
"static/*" "static/*"
] ]

View File

@ -3,7 +3,6 @@
import { app, BrowserWindow, nativeImage } from 'electron'; import { app, BrowserWindow, nativeImage } from 'electron';
import * as path from 'path'; import * as path from 'path';
import { format as formatUrl } from 'url'; import { format as formatUrl } from 'url';
import { autoUpdater } from 'electron-updater';
import ipcHandlers from './ipc-handlers'; import ipcHandlers from './ipc-handlers';
@ -68,10 +67,6 @@ function createMainWindow () {
// Initialize ipcHandlers // Initialize ipcHandlers
ipcHandlers(); ipcHandlers();
autoUpdater.checkForUpdatesAndNotify();
autoUpdater.logger = require('electron-log');
autoUpdater.logger.transports.file.level = 'info';
return window; return window;
}; };
@ -92,21 +87,3 @@ app.on('activate', () => {
app.on('ready', () => { app.on('ready', () => {
mainWindow = createMainWindow(); mainWindow = createMainWindow();
}); });
// auto-updater events
autoUpdater.on('checking-for-update', () => {
});
autoUpdater.on('update-available', () => {
mainWindow.webContents.send('update_available');
});
autoUpdater.on('update-not-available', () => {
});
autoUpdater.on('download-progress', (progressObj) => {
});
autoUpdater.on('update-downloaded', () => {
mainWindow.webContents.send('update_downloaded');
});

View File

@ -1,9 +1,11 @@
import connection from './connection'; import connection from './connection';
import structure from './structure'; import structure from './structure';
import updates from './updates';
const connections = {}; const connections = {};
export default () => { export default () => {
connection(connections); connection(connections);
structure(connections); structure(connections);
updates();
}; };

View File

@ -0,0 +1,43 @@
import { ipcMain } from 'electron';
import { autoUpdater } from 'electron-updater';
let mainWindow;
export default () => {
ipcMain.on('checkForUpdates', event => {
mainWindow = event;
autoUpdater.checkForUpdatesAndNotify().catch(() => {
mainWindow.reply('checkFailed');
});
});
ipcMain.on('restartToUpdate', () => {
autoUpdater.quitAndInstall();
});
// auto-updater events
autoUpdater.on('checking-for-update', () => {
mainWindow.reply('checkingForUpdate');
});
autoUpdater.on('update-available', () => {
mainWindow.reply('updateAvailable');
});
autoUpdater.on('update-not-available', () => {
mainWindow.reply('updateNotAvailable');
});
autoUpdater.on('download-progress', (data) => {
mainWindow.reply('downloadProgress', data);
});
autoUpdater.on('update-downloaded', () => {
mainWindow.reply('updateDownloaded');
});
autoUpdater.logger = require('electron-log');
autoUpdater.logger.transports.console.format = '{h}:{i}:{s} {text}';
autoUpdater.logger.transports.file.level = 'info';
};

View File

@ -24,6 +24,7 @@
<script> <script>
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
import { ipcRenderer } from 'electron';
export default { export default {
name: 'App', name: 'App',
@ -51,6 +52,9 @@ export default {
connections: 'connections/getConnections' connections: 'connections/getConnections'
}) })
}, },
mounted () {
ipcRenderer.send('checkForUpdates');
},
methods: { methods: {
...mapActions({ ...mapActions({
showNewConnModal: 'application/showNewConnModal' showNewConnModal: 'application/showNewConnModal'

View File

@ -78,7 +78,7 @@
</div> </div>
<div v-if="selectedTab === 'update'" class="panel-body py-4"> <div v-if="selectedTab === 'update'" class="panel-body py-4">
<!-- --> <ModalSettingsUpdate />
</div> </div>
<div v-if="selectedTab === 'about'" class="panel-body py-4"> <div v-if="selectedTab === 'about'" class="panel-body py-4">
@ -101,10 +101,14 @@
<script> <script>
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
import localesNames from '@/i18n/supported-locales'; import localesNames from '@/i18n/supported-locales';
import ModalSettingsUpdate from '@/components/ModalSettingsUpdate';
const { shell } = require('electron'); const { shell } = require('electron');
export default { export default {
name: 'ModalSettings', name: 'ModalSettings',
components: {
ModalSettingsUpdate
},
data () { data () {
return { return {
isUpdate: false, isUpdate: false,

View File

@ -0,0 +1,84 @@
<template>
<div class="empty">
<div class="empty-icon">
<i class="material-icons md-48">system_update_alt</i>
</div>
<p class="empty-title h5">
{{ updateMessage }}
</p>
<div v-if="updateStatus === 'downloading'">
<progress
class="progress"
:value="downloadPercentage"
max="100"
/>
<p class="empty-subtitle">
{{ downloadPercentage }}%
</p>
</div>
<div class="empty-action">
<button
v-if="['noupdate', 'checking', 'nocheck'].includes(updateStatus)"
class="btn btn-primary"
:class="{'loading': updateStatus === 'checking'}"
@click="checkForUpdates"
>
{{ $t('message.checkForUpdates') }}
</button>
<button
v-if="updateStatus === 'downloaded'"
class="btn btn-primary"
@click="restartToUpdate"
>
{{ $t('message.restartToInstall') }}
</button>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex';
import { ipcRenderer } from 'electron';
export default {
name: 'ModalSettingsUpdate',
computed: {
...mapGetters({
updateStatus: 'application/getUpdateStatus',
downloadPercentage: 'application/getDownloadProgress'
}),
updateMessage () {
switch (this.updateStatus) {
case 'noupdate':
return this.$t('message.noUpdatesAvailable');
case 'checking':
return this.$t('message.checkingForUpdate');
case 'nocheck':
return this.$t('message.checkFailure');
case 'available':
return this.$t('message.updateAvailable');
case 'downloading':
return this.$t('message.downloadingUpdate');
case 'downloaded':
return this.$t('message.updateDownloaded');
default:
return this.updateStatus;
}
}
},
methods: {
checkForUpdates () {
ipcRenderer.send('checkForUpdates');
},
restartToUpdate () {
ipcRenderer.send('restartToUpdate');
}
}
};
</script>
<style lang="scss">
.empty{
color: $body-font-color;
}
</style>

View File

@ -70,10 +70,12 @@ export default {
case 'char': case 'char':
case 'varchar': case 'varchar':
case 'text': case 'text':
case 'mediumtext':
return val.substring(0, 128); return val.substring(0, 128);
case 'date': case 'date':
return moment(val).format('YYYY-MM-DD'); return moment(val).format('YYYY-MM-DD');
case 'datetime': case 'datetime':
case 'timestamp':
return moment(val).format('YYYY-MM-DD HH:mm:ss.SSS'); return moment(val).format('YYYY-MM-DD HH:mm:ss.SSS');
case 'blob': case 'blob':
case 'mediumblob': case 'mediumblob':

View File

@ -43,7 +43,15 @@ module.exports = {
deleteConnection: 'Delete connection', deleteConnection: 'Delete connection',
deleteConnectionCorfirm: 'Do you confirm the cancellation of', deleteConnectionCorfirm: 'Do you confirm the cancellation of',
connectionSuccessfullyMade: 'Connection successfully made!', connectionSuccessfullyMade: 'Connection successfully made!',
madeWithJS: 'Made with 💛 and JavaScript!' madeWithJS: 'Made with 💛 and JavaScript!',
checkForUpdates: 'Check for updates',
noUpdatesAvailable: 'No updates available',
checkingForUpdate: 'Checking for updates',
checkFailure: 'Check failed, please try later',
updateAvailable: 'Update available',
downloadingUpdate: 'Downloading update',
updateDownloaded: 'Update downloaded',
restartToInstall: 'Restart Antares to install'
}, },
// Date and Time // Date and Time
short: { short: {

View File

@ -14,6 +14,7 @@
"char": seagreen, "char": seagreen,
"varchar": seagreen, "varchar": seagreen,
"text": seagreen, "text": seagreen,
"mediumtext": seagreen,
"int": cornflowerblue, "int": cornflowerblue,
"tinyint": cornflowerblue, "tinyint": cornflowerblue,
@ -23,6 +24,7 @@
"datetime": coral, "datetime": coral,
"date": coral, "date": coral,
"time": coral, "time": coral,
"timestamp": coral,
"bit": lightskyblue, "bit": lightskyblue,

View File

@ -7,6 +7,7 @@
@import "mdi-additions"; @import "mdi-additions";
@import "db-icons"; @import "db-icons";
@import "~spectre.css/src/spectre"; @import "~spectre.css/src/spectre";
@import "~spectre.css/src/spectre-exp";
body{ body{
user-select: none; user-select: none;

View File

@ -10,6 +10,8 @@ import connections from './modules/connections.store';
import workspaces from './modules/workspaces.store'; import workspaces from './modules/workspaces.store';
import notifications from './modules/notifications.store'; import notifications from './modules/notifications.store';
import ipcUpdates from './plugins/ipcUpdates';
const vuexLocalStorage = new VuexPersist({ const vuexLocalStorage = new VuexPersist({
key: 'application', // The key to store the state on in the storage provider. key: 'application', // The key to store the state on in the storage provider.
storage: window.localStorage, storage: window.localStorage,
@ -30,5 +32,8 @@ export default new Vuex.Store({
workspaces, workspaces,
notifications notifications
}, },
plugins: [vuexLocalStorage.plugin] plugins: [
vuexLocalStorage.plugin,
ipcUpdates
]
}); });

View File

@ -10,7 +10,9 @@ export default {
is_edit_modal: false, is_edit_modal: false,
is_setting_modal: false, is_setting_modal: false,
selected_setting_tab: 'general', selected_setting_tab: 'general',
selected_conection: {} selected_conection: {},
update_status: 'noupdate', // noupdate, available, checking, nocheck, downloading, downloaded
download_progress: 0
}, },
getters: { getters: {
isLoading: state => state.is_loading, isLoading: state => state.is_loading,
@ -20,7 +22,9 @@ export default {
isNewModal: state => state.is_new_modal, isNewModal: state => state.is_new_modal,
isEditModal: state => state.is_edit_modal, isEditModal: state => state.is_edit_modal,
isSettingModal: state => state.is_setting_modal, isSettingModal: state => state.is_setting_modal,
selectedSettingTab: state => state.selected_setting_tab selectedSettingTab: state => state.selected_setting_tab,
getUpdateStatus: state => state.update_status,
getDownloadProgress: state => state.download_progress
}, },
mutations: { mutations: {
SET_LOADING_STATUS (state, payload) { SET_LOADING_STATUS (state, payload) {
@ -45,6 +49,12 @@ export default {
}, },
HIDE_SETTING_MODAL (state) { HIDE_SETTING_MODAL (state) {
state.is_setting_modal = false; state.is_setting_modal = false;
},
CHANGE_UPDATE_STATUS (state, status) {
state.update_status = status;
},
CHANGE_PROGRESS_PERCENTAGE (state, percentage) {
state.download_progress = percentage;
} }
}, },
actions: { actions: {

View File

@ -0,0 +1,23 @@
import { ipcRenderer } from 'electron';
export default store => {
ipcRenderer.on('checkingForUpdate', () => {
store.commit('application/CHANGE_UPDATE_STATUS', 'checking');
});
ipcRenderer.on('updateAvailable', () => {
store.commit('application/CHANGE_UPDATE_STATUS', 'available');
});
ipcRenderer.on('updateNotAvailable', () => {
store.commit('application/CHANGE_UPDATE_STATUS', 'noupdate');
});
ipcRenderer.on('checkFailed', () => {
store.commit('application/CHANGE_UPDATE_STATUS', 'nocheck');
});
ipcRenderer.on('downloadProgress', (event, data) => {
store.commit('application/CHANGE_UPDATE_STATUS', 'downloading');
store.commit('application/CHANGE_PROGRESS_PERCENTAGE', data.percent);
});
ipcRenderer.on('updateDownloaded', () => {
store.commit('application/CHANGE_UPDATE_STATUS', 'downloaded');
});
};