mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 23:06:00 +00:00
checking for update
This commit is contained in:
@@ -28,6 +28,7 @@ let apiLoaded = false;
|
|||||||
let mainModule;
|
let mainModule;
|
||||||
// let getLogger;
|
// let getLogger;
|
||||||
// let loadLogsContent;
|
// let loadLogsContent;
|
||||||
|
let appUpdateStatus = '';
|
||||||
|
|
||||||
process.on('uncaughtException', function (error) {
|
process.on('uncaughtException', function (error) {
|
||||||
console.error('uncaughtException', error);
|
console.error('uncaughtException', error);
|
||||||
@@ -201,6 +202,9 @@ ipcMain.on('app-started', async (event, arg) => {
|
|||||||
if (initialConfig['winIsMaximized']) {
|
if (initialConfig['winIsMaximized']) {
|
||||||
mainWindow.webContents.send('setIsMaximized', true);
|
mainWindow.webContents.send('setIsMaximized', true);
|
||||||
}
|
}
|
||||||
|
if (autoUpdater.isUpdaterActive()) {
|
||||||
|
mainWindow.webContents.send('setAppUpdaterActive');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
ipcMain.on('window-action', async (event, arg) => {
|
ipcMain.on('window-action', async (event, arg) => {
|
||||||
if (!mainWindow) {
|
if (!mainWindow) {
|
||||||
@@ -274,6 +278,15 @@ ipcMain.handle('showItemInFolder', async (event, path) => {
|
|||||||
ipcMain.handle('openExternal', async (event, url) => {
|
ipcMain.handle('openExternal', async (event, url) => {
|
||||||
electron.shell.openExternal(url);
|
electron.shell.openExternal(url);
|
||||||
});
|
});
|
||||||
|
ipcMain.handle('downloadUpdate', async (event, url) => {
|
||||||
|
autoUpdater.downloadUpdate();
|
||||||
|
});
|
||||||
|
ipcMain.on('applyUpdate', async (event, url) => {
|
||||||
|
autoUpdater.quitAndInstall(false, true);
|
||||||
|
});
|
||||||
|
ipcMain.on('check-for-updates', async (event, url) => {
|
||||||
|
autoUpdater.checkForUpdates();
|
||||||
|
});
|
||||||
|
|
||||||
function fillMissingSettings(value) {
|
function fillMissingSettings(value) {
|
||||||
const res = {
|
const res = {
|
||||||
@@ -335,7 +348,7 @@ function createWindow() {
|
|||||||
titleBarStyle: useNativeMenu ? undefined : 'hidden',
|
titleBarStyle: useNativeMenu ? undefined : 'hidden',
|
||||||
...bounds,
|
...bounds,
|
||||||
icon: os.platform() == 'win32' ? 'icon.ico' : path.resolve(__dirname, '../icon.png'),
|
icon: os.platform() == 'win32' ? 'icon.ico' : path.resolve(__dirname, '../icon.png'),
|
||||||
partition: 'persist:dbgate',
|
partition: isProApp() ? 'persist:dbgate-premium' : 'persist:dbgate',
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
contextIsolation: false,
|
contextIsolation: false,
|
||||||
@@ -438,6 +451,38 @@ function createWindow() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function changeAppUpdateStatus(message) {
|
||||||
|
appUpdateStatus = message;
|
||||||
|
mainWindow.webContents.send('app-update-status', appUpdateStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
autoUpdater.on('checking-for-update', () => {
|
||||||
|
console.log('Checking for updates');
|
||||||
|
changeAppUpdateStatus('Checking for updates...');
|
||||||
|
});
|
||||||
|
|
||||||
|
autoUpdater.on('update-available', info => {
|
||||||
|
console.log('Update available', info);
|
||||||
|
changeAppUpdateStatus(`New version ${info.version} available`);
|
||||||
|
mainWindow.webContents.send('update-available', info.version);
|
||||||
|
});
|
||||||
|
|
||||||
|
autoUpdater.on('update-not-available', info => {
|
||||||
|
console.log('Update not available', info);
|
||||||
|
changeAppUpdateStatus(`No new updates`);
|
||||||
|
});
|
||||||
|
|
||||||
|
autoUpdater.on('update-downloaded', info => {
|
||||||
|
console.log('Update downloaded from', info);
|
||||||
|
changeAppUpdateStatus(`Downloaded new version ${info.version}`);
|
||||||
|
mainWindow.webContents.send('downloaded-new-version', info.version);
|
||||||
|
});
|
||||||
|
|
||||||
|
autoUpdater.on('error', error => {
|
||||||
|
changeAppUpdateStatus(`Autoupdate error`);
|
||||||
|
console.error('Update error', error);
|
||||||
|
});
|
||||||
|
|
||||||
function onAppReady() {
|
function onAppReady() {
|
||||||
if (!process.env.DEVMODE) {
|
if (!process.env.DEVMODE) {
|
||||||
autoUpdater.autoDownload = false;
|
autoUpdater.autoDownload = false;
|
||||||
|
|||||||
@@ -105,6 +105,8 @@ module.exports = ({ editMenu }) => [
|
|||||||
{ command: 'settings.commands', hideDisabled: true },
|
{ command: 'settings.commands', hideDisabled: true },
|
||||||
{ command: 'tabs.changelog', hideDisabled: true },
|
{ command: 'tabs.changelog', hideDisabled: true },
|
||||||
{ command: 'about.show', hideDisabled: true },
|
{ command: 'about.show', hideDisabled: true },
|
||||||
|
{ divider: true },
|
||||||
|
{ command: 'file.checkForUpdates', hideDisabled: true },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
import AppStartInfo from './widgets/AppStartInfo.svelte';
|
import AppStartInfo from './widgets/AppStartInfo.svelte';
|
||||||
import SettingsListener from './utility/SettingsListener.svelte';
|
import SettingsListener from './utility/SettingsListener.svelte';
|
||||||
import { handleAuthOnStartup } from './clientAuth';
|
import { handleAuthOnStartup } from './clientAuth';
|
||||||
|
import { initializeAppUpdates } from './utility/appUpdate';
|
||||||
|
|
||||||
export let isAdminPage = false;
|
export let isAdminPage = false;
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@
|
|||||||
subscribeConnectionPingers();
|
subscribeConnectionPingers();
|
||||||
subscribePermissionCompiler();
|
subscribePermissionCompiler();
|
||||||
installNewVolatileConnectionListener();
|
installNewVolatileConnectionListener();
|
||||||
|
initializeAppUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadedApi = loadedApiValue;
|
loadedApi = loadedApiValue;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
currentTheme,
|
currentTheme,
|
||||||
emptyConnectionGroupNames,
|
emptyConnectionGroupNames,
|
||||||
extensions,
|
extensions,
|
||||||
|
getAppUpdaterActive,
|
||||||
getExtensions,
|
getExtensions,
|
||||||
getVisibleToolbar,
|
getVisibleToolbar,
|
||||||
visibleToolbar,
|
visibleToolbar,
|
||||||
@@ -585,6 +586,17 @@ registerCommand({
|
|||||||
onClick: () => disconnectServerConnection(getCurrentConfig()?.singleConnection?._id),
|
onClick: () => disconnectServerConnection(getCurrentConfig()?.singleConnection?._id),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerCommand({
|
||||||
|
id: 'file.checkForUpdates',
|
||||||
|
category: 'App',
|
||||||
|
name: 'Check for updates',
|
||||||
|
// testEnabled: () => true,
|
||||||
|
testEnabled: () => getAppUpdaterActive(),
|
||||||
|
onClick: () => getElectron().send('check-for-updates'),
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function registerFileCommands({
|
export function registerFileCommands({
|
||||||
idPrefix,
|
idPrefix,
|
||||||
category,
|
category,
|
||||||
|
|||||||
@@ -123,6 +123,8 @@ export const commandsCustomized = derived([commands, commandsSettings], ([$comma
|
|||||||
...$commandsSettings[k],
|
...$commandsSettings[k],
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
export const appUpdateStatus = writable('');
|
||||||
|
export const appUpdaterActive = writable(false);
|
||||||
|
|
||||||
export const draggingTab = writable(null);
|
export const draggingTab = writable(null);
|
||||||
export const draggingTabTarget = writable(null);
|
export const draggingTabTarget = writable(null);
|
||||||
@@ -303,3 +305,9 @@ currentArchive.subscribe(value => {
|
|||||||
currentArchiveValue = value;
|
currentArchiveValue = value;
|
||||||
});
|
});
|
||||||
export const getCurrentArchive = () => currentArchiveValue;
|
export const getCurrentArchive = () => currentArchiveValue;
|
||||||
|
|
||||||
|
let appUpdaterActiveValue = false;
|
||||||
|
appUpdaterActive.subscribe(value => {
|
||||||
|
appUpdaterActiveValue = value;
|
||||||
|
});
|
||||||
|
export const getAppUpdaterActive = () => appUpdaterActiveValue;
|
||||||
48
packages/web/src/utility/appUpdate.ts
Normal file
48
packages/web/src/utility/appUpdate.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { appUpdaterActive, appUpdateStatus } from '../stores';
|
||||||
|
import getElectron from './getElectron';
|
||||||
|
import { showSnackbar } from './snackbar';
|
||||||
|
|
||||||
|
export function initializeAppUpdates() {
|
||||||
|
const electron = getElectron();
|
||||||
|
if (!electron) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
electron.addEventListener('update-available', (e, version) => {
|
||||||
|
showSnackbar({
|
||||||
|
message: `Update available: ${version}`,
|
||||||
|
allowClose: true,
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
label: 'Download',
|
||||||
|
onClick: () => {
|
||||||
|
electron.send('downloadUpdate');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
electron.addEventListener('app-update-status', (e, text) => {
|
||||||
|
appUpdateStatus.set(text);
|
||||||
|
});
|
||||||
|
|
||||||
|
electron.addEventListener('downloaded-new-version', (e, version) => {
|
||||||
|
showSnackbar({
|
||||||
|
message: `New version ${version} downloaded`,
|
||||||
|
allowClose: true,
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
label: 'Restart',
|
||||||
|
onClick: () => {
|
||||||
|
electron.send('applyUpdate');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
electron.addEventListener('setAppUpdaterActive', (e, error) => {
|
||||||
|
appUpdaterActive.set(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
activeTabId,
|
activeTabId,
|
||||||
|
appUpdateStatus,
|
||||||
currentArchive,
|
currentArchive,
|
||||||
currentDatabase,
|
currentDatabase,
|
||||||
currentThemeDefinition,
|
currentThemeDefinition,
|
||||||
@@ -169,6 +170,12 @@
|
|||||||
{item.text}
|
{item.text}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
|
{#if $appUpdateStatus}
|
||||||
|
<div class="item">
|
||||||
|
{$appUpdateStatus}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user