diff --git a/build/locales/en/translations.json b/build/locales/en/translations.json index 62603f97..77f80df5 100644 --- a/build/locales/en/translations.json +++ b/build/locales/en/translations.json @@ -170,6 +170,28 @@ "description": "Importing DB ...", "unzippedBytes": "DB size {{prettyUnzippedBytes}}" } + }, + "removeDB": { + "modalDialog": { + "clearDataTitle": "Clear all data", + "removeDBTitle": "Remove database", + "clearDataMessage": "Are you sure you want to clear all data?", + "removeDBMessage": "Are you sure you want to remove the database?" + }, + "messageModalDialog": { + "dbRemovingTitle": "DB removing", + "dbDataHasBeenRemovedMessage": "DB data has been removed", + "dbDataHasNotBeenRemovedMessage": "DB data has not been removed", + "dbHasNotBeenRestoredTitle": "DB has not been restored", + "removeDBTitle": "Remove database", + "removeDBMessage": "Should all tables be removed?", + "confirmButtonText": "OK", + "cancelButtonText": "Cancel" + }, + "loadingWindow": { + "removingDBDescription": "Removing DB ...", + "clearingAllDataDescription": "Clearing all data ..." + } } }, "menu": { diff --git a/build/locales/ru/translations.json b/build/locales/ru/translations.json index 687ba602..307e80f4 100644 --- a/build/locales/ru/translations.json +++ b/build/locales/ru/translations.json @@ -170,6 +170,28 @@ "description": "Импортирование БД ...", "unzippedBytes": "размер БД {{prettyUnzippedBytes}}" } + }, + "removeDB": { + "modalDialog": { + "clearDataTitle": "Очистить все данные", + "removeDBTitle": "Удалить базу данных", + "clearDataMessage": "Вы уверены, что хотите удалить все данные?", + "removeDBMessage": "Вы уверены, что хотите удалить базу данных?" + }, + "messageModalDialog": { + "dbRemovingTitle": "Удаление БД", + "dbDataHasBeenRemovedMessage": "Данные БД были удалены", + "dbDataHasNotBeenRemovedMessage": "Данные БД не были удалены", + "dbHasNotBeenRestoredTitle": "БД не восстановлена", + "removeDBTitle": "Удалить базу данных", + "removeDBMessage": "Следует ли удалить все таблицы?", + "confirmButtonText": "OK", + "cancelButtonText": "Отмена" + }, + "loadingWindow": { + "removingDBDescription": "Удаление БД ...", + "clearingAllDataDescription": "Очистка всех данные ..." + } } }, "menu": { diff --git a/src/manage-worker-messages.js b/src/manage-worker-messages.js index 14f4e316..bcfeaf3d 100644 --- a/src/manage-worker-messages.js +++ b/src/manage-worker-messages.js @@ -93,18 +93,20 @@ module.exports = (ipc) => { await showWindow(win) const haveNotAllDbDataBeenRemoved = state === PROCESS_MESSAGES.ALL_TABLE_HAVE_NOT_BEEN_REMOVED - const messChunk = haveNotAllDbDataBeenRemoved - ? ' not' - : '' + const message = haveNotAllDbDataBeenRemoved + ? i18next.t('common.removeDB.messageModalDialog.dbDataHasNotBeenRemovedMessage') + : i18next.t('common.removeDB.messageModalDialog.dbDataHasBeenRemovedMessage') const type = haveNotAllDbDataBeenRemoved ? 'error' : 'info' await showMessageModalDialog(win, { type, - title: 'DB removing', - message: `DB data have${messChunk} been removed`, - buttons: ['OK'], + title: i18next.t('common.removeDB.messageModalDialog.dbRemovingTitle'), + message, + buttons: [ + i18next.t('common.removeDB.messageModalDialog.confirmButtonText') + ], defaultId: 0, cancelId: 0 }) @@ -219,16 +221,19 @@ module.exports = (ipc) => { } if (state === PROCESS_MESSAGES.REQUEST_SHOULD_ALL_TABLES_BE_REMOVED) { const title = data.isNotDbRestored - ? 'DB has not been restored' - : 'Remove database' + ? i18next.t('common.removeDB.messageModalDialog.dbHasNotBeenRestoredTitle') + : i18next.t('common.removeDB.messageModalDialog.removeDBTitle') const { btnId } = await showMessageModalDialog(win, { type: 'question', title, - message: 'Should all tables be removed?', - buttons: ['Cancel', 'OK'] + message: i18next.t('common.removeDB.messageModalDialog.removeDBMessage'), + buttons: [ + i18next.t('common.removeDB.messageModalDialog.cancelButtonText'), + i18next.t('common.removeDB.messageModalDialog.confirmButtonText') + ] }) if (btnId === 0) { diff --git a/src/remove-db.js b/src/remove-db.js index dd90f105..56830a30 100644 --- a/src/remove-db.js +++ b/src/remove-db.js @@ -1,10 +1,13 @@ 'use strict' -const electron = require('electron') +const { BrowserWindow } = require('electron') +const i18next = require('i18next') const ipcs = require('./ipcs') const showErrorModalDialog = require('./show-error-modal-dialog') const showMessageModalDialog = require('./show-message-modal-dialog') +const wins = require('./window-creators/windows') +const isMainWinAvailable = require('./helpers/is-main-win-available') const pauseApp = require('./pause-app') const relaunch = require('./relaunch') const { rm } = require('./helpers') @@ -85,13 +88,15 @@ module.exports = ({ shouldAllTablesBeCleared }) => { return async () => { - const win = electron.BrowserWindow.getFocusedWindow() + const win = isMainWinAvailable(wins.mainWindow) + ? wins.mainWindow + : BrowserWindow.getFocusedWindow() const title = shouldAllTablesBeCleared - ? 'Clear all data' - : 'Remove database' + ? i18next.t('common.removeDB.modalDialog.clearDataTitle') + : i18next.t('common.removeDB.modalDialog.removeDBTitle') const message = shouldAllTablesBeCleared - ? 'Are you sure you want to clear all data?' - : 'Are you sure you want to remove the database?' + ? i18next.t('common.removeDB.modalDialog.clearDataMessage') + : i18next.t('common.removeDB.modalDialog.removeDBMessage') try { const { @@ -114,6 +119,11 @@ module.exports = ({ } await _clearAllTables() + }, + loadingWinParams: { + description: shouldAllTablesBeCleared + ? i18next.t('common.removeDB.loadingWindow.clearingAllDataDescription') + : i18next.t('common.removeDB.loadingWindow.removingDBDescription') } }) @@ -124,7 +134,10 @@ module.exports = ({ relaunch() } catch (err) { try { - await showErrorModalDialog(win, title, err) + const _win = isMainWinAvailable(wins.loadingWindow) + ? wins.loadingWindow + : win + await showErrorModalDialog(_win, title, err) } catch (err) { console.error(err) }