2
0
mirror of https://github.com/frappe/books.git synced 2025-01-30 18:48:54 +00:00

incr: remove Check for Updates

This commit is contained in:
18alantom 2022-05-27 16:17:24 +05:30 committed by Alan
parent b7d41db996
commit f21e507f2a
8 changed files with 24 additions and 133 deletions

View File

@ -1,42 +1,10 @@
import { autoUpdater, UpdateInfo } from 'electron-updater';
import { autoUpdater } from 'electron-updater';
import { Main } from '../main';
import { IPC_CHANNELS } from '../utils/messages';
export default function registerAutoUpdaterListeners(main: Main) {
autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = false;
autoUpdater.on('checking-for-update', () => {
if (!main.checkedForUpdate) {
return;
}
main.mainWindow!.webContents.send(IPC_CHANNELS.CHECKING_FOR_UPDATE);
});
autoUpdater.on('update-available', (info: UpdateInfo) => {
if (!main.checkedForUpdate) {
main.checkedForUpdate = true;
}
main.mainWindow!.webContents.send(
IPC_CHANNELS.UPDATE_AVAILABLE,
info.version
);
});
autoUpdater.on('update-not-available', () => {
if (!main.checkedForUpdate) {
main.checkedForUpdate = true;
return;
}
main.mainWindow!.webContents.send(IPC_CHANNELS.UPDATE_NOT_AVAILABLE);
});
autoUpdater.on('update-downloaded', () => {
main.mainWindow!.webContents.send(IPC_CHANNELS.UPDATE_DOWNLOADED);
});
autoUpdater.autoDownload = true;
autoUpdater.autoInstallOnAppQuit = true;
autoUpdater.on('error', (error) => {
if (!main.checkedForUpdate) {
@ -44,6 +12,6 @@ export default function registerAutoUpdaterListeners(main: Main) {
return;
}
main.mainWindow!.webContents.send(IPC_CHANNELS.UPDATE_ERROR, error);
main.mainWindow!.webContents.send(IPC_CHANNELS.MAIN_PROCESS_ERROR, error);
});
}

View File

@ -62,11 +62,10 @@ export default function registerIpcMainActionListeners(main: Main) {
sendError(bodyJson);
});
ipcMain.handle(IPC_ACTIONS.CHECK_FOR_UPDATES, (event, force) => {
ipcMain.handle(IPC_ACTIONS.CHECK_FOR_UPDATES, () => {
if (!main.isDevelopment && !main.checkedForUpdate) {
autoUpdater.checkForUpdates();
} else if (force) {
autoUpdater.checkForUpdates();
main.checkedForUpdate = true;
}
});

View File

@ -1,5 +1,4 @@
import { ipcMain, Menu, shell } from 'electron';
import { autoUpdater } from 'electron-updater';
import { Main } from '../main';
import { IPC_MESSAGES } from '../utils/messages';
@ -21,27 +20,19 @@ export default function registerIpcMainMessageListeners(main: Main) {
main.mainWindow!.reload();
});
ipcMain.on(IPC_MESSAGES.CLOSE_CURRENT_WINDOW, (event) => {
ipcMain.on(IPC_MESSAGES.CLOSE_CURRENT_WINDOW, () => {
main.mainWindow!.close();
});
ipcMain.on(IPC_MESSAGES.MINIMIZE_CURRENT_WINDOW, (event) => {
ipcMain.on(IPC_MESSAGES.MINIMIZE_CURRENT_WINDOW, () => {
main.mainWindow!.minimize();
});
ipcMain.on(IPC_MESSAGES.OPEN_EXTERNAL, (event, link) => {
ipcMain.on(IPC_MESSAGES.OPEN_EXTERNAL, (_, link) => {
shell.openExternal(link);
});
ipcMain.on(IPC_MESSAGES.SHOW_ITEM_IN_FOLDER, (event, filePath) => {
ipcMain.on(IPC_MESSAGES.SHOW_ITEM_IN_FOLDER, (_, filePath) => {
return shell.showItemInFolder(filePath);
});
ipcMain.on(IPC_MESSAGES.DOWNLOAD_UPDATE, (event) => {
autoUpdater.downloadUpdate();
});
ipcMain.on(IPC_MESSAGES.INSTALL_UPDATE, (event) => {
autoUpdater.quitAndInstall(true, true);
});
}

View File

@ -8,28 +8,10 @@
:emit-change="true"
@change="forwardChangeEvent"
/>
<div
class="flex flex-row justify-between items-center w-full text-gray-900 p-6"
>
<LanguageSelector
class="text-sm w-40 bg-gray-100 rounded-md"
input-class="bg-transparent"
/>
<button
class="
text-sm
bg-gray-100
hover:bg-gray-200
rounded-md
px-4
h-8
w-40
"
@click="checkForUpdates(true)"
>
{{ t`Check for Updates` }}
</button>
</div>
<LanguageSelector
class="text-sm w-28 bg-gray-100 rounded-md mb-6 ml-6"
input-class="py-1.5 bg-transparent"
/>
</div>
</template>
@ -39,7 +21,6 @@ import { ModelNameEnum } from 'models/types';
import LanguageSelector from 'src/components/Controls/LanguageSelector.vue';
import TwoColumnForm from 'src/components/TwoColumnForm';
import { fyo } from 'src/initFyo';
import { checkForUpdates } from 'src/utils/ipcCalls';
import { getCountryInfo } from 'utils/misc';
export default {
@ -69,7 +50,6 @@ export default {
},
},
methods: {
checkForUpdates,
forwardChangeEvent(...args) {
this.$emit('change', ...args);
},

View File

@ -1,57 +1,14 @@
import { ipcRenderer } from 'electron';
import { handleError } from 'src/errorHandling';
import { fyo } from 'src/initFyo';
import { showToast } from 'src/utils/ui';
import { IPC_CHANNELS, IPC_MESSAGES } from 'utils/messages';
import { IPC_CHANNELS } from 'utils/messages';
export default function registerIpcRendererListeners() {
ipcRenderer.on(IPC_CHANNELS.CHECKING_FOR_UPDATE, (_) => {
showToast({ message: fyo.t`Checking for updates` });
});
ipcRenderer.on(IPC_CHANNELS.UPDATE_AVAILABLE, (_, version) => {
const message = version
? fyo.t`Version ${version} available`
: fyo.t`New version available`;
const action = () => {
ipcRenderer.send(IPC_MESSAGES.DOWNLOAD_UPDATE);
showToast({ message: fyo.t`Downloading update` });
};
showToast({
message,
action,
actionText: fyo.t`Download Update`,
duration: 10000,
type: 'success',
});
});
ipcRenderer.on(IPC_CHANNELS.UPDATE_NOT_AVAILABLE, (_) => {
showToast({ message: fyo.t`No updates available` });
});
ipcRenderer.on(IPC_CHANNELS.UPDATE_DOWNLOADED, (_) => {
const action = () => {
ipcRenderer.send(IPC_MESSAGES.INSTALL_UPDATE);
};
showToast({
message: fyo.t`Update downloaded`,
action,
actionText: fyo.t`Install Update`,
duration: 10000,
type: 'success',
});
});
ipcRenderer.on(IPC_CHANNELS.UPDATE_ERROR, async (_, error) => {
error.name = 'Updation Error';
await handleError(true, error as Error);
});
ipcRenderer.on(IPC_CHANNELS.MAIN_PROCESS_ERROR, async (_, error) => {
console.error('main process error');
console.error(error);
if (fyo.store.isDevelopment) {
console.error(error);
}
await handleError(true, error as Error);
});

View File

@ -8,8 +8,8 @@ import { setLanguageMap } from './language';
import { WindowAction } from './types';
import { showToast } from './ui';
export async function checkForUpdates(force = false) {
await ipcRenderer.invoke(IPC_ACTIONS.CHECK_FOR_UPDATES, force);
export async function checkForUpdates() {
await ipcRenderer.invoke(IPC_ACTIONS.CHECK_FOR_UPDATES);
await setLanguageMap();
}

View File

@ -105,6 +105,9 @@ export async function showToast(options: ToastOptions) {
replaceAndAppendMount(toast, 'toast-target');
}
// @ts-ignore
window.st = showToast
function replaceAndAppendMount(app: App<Element>, replaceId: string) {
const fragment = document.createDocumentFragment();
const target = document.getElementById(replaceId);

View File

@ -7,8 +7,6 @@ export enum IPC_MESSAGES {
RELOAD_MAIN_WINDOW = 'reload-main-window',
CLOSE_CURRENT_WINDOW = 'close-current-window',
MINIMIZE_CURRENT_WINDOW = 'minimize-current-window',
DOWNLOAD_UPDATE = 'download-update',
INSTALL_UPDATE = 'install-update',
}
// ipcRenderer.invoke(...)
@ -38,11 +36,6 @@ export enum IPC_ACTIONS {
// ipcMain.send(...)
export enum IPC_CHANNELS {
CHECKING_FOR_UPDATE = 'checking-for-update',
UPDATE_AVAILABLE = 'update-available',
UPDATE_NOT_AVAILABLE = 'update-not-available',
UPDATE_DOWNLOADED = 'update-downloaded',
UPDATE_ERROR = 'update-error',
MAIN_PROCESS_ERROR = 'main-process-error',
CONSOLE_LOG = 'console-log',
}