Skip to content

Commit

Permalink
chore: Added confirmation dialog for config import. (#626)
Browse files Browse the repository at this point in the history
* chore: Added confirmation dialog for config import.

* chore: clean up PR after revies

* chore: update translation with proper caseing

Co-authored-by: Andrew Chou <andrewchou@fastmail.com>

* chore: removed unnecessary line

Co-authored-by: Andrew Chou <andrewchou@fastmail.com>
  • Loading branch information
ErikSin and achou11 authored Dec 2, 2021
1 parent c06b647 commit 24fba77
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 31 deletions.
1 change: 1 addition & 0 deletions messages/main/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"menu-file": "File",
"menu-change-language": "Change language...",
"menu-change-language-title": "Enter the language (e.g., 'en' or 'es')",
"menu-config-complete": "Successfully imported config: ",
"menu-import-tiles-file": "File (.tar)",
"menu-import-tiles-directory": "Directory of tiles",
"menu-import-tiles": "Import Offline Map Tiles...",
Expand Down
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 37 additions & 31 deletions src/main/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const i18n = require('./i18n')
const logger = require('../logger')
const config = require('../../config')
const userConfig = require('./user-config')

const t = i18n.t

module.exports = function createMenu (ipc) {
Expand Down Expand Up @@ -40,9 +39,7 @@ function menuTemplate (ipc) {
var opts = {
title: t('menu-import-tiles'),
properties: ['openFile'],
filters: [
{ name: 'Tar', extensions: ['tar'] }
]
filters: [{ name: 'Tar', extensions: ['tar'] }]
}
const result = await dialog.showOpenDialog(opts)
if (result.canceled) return
Expand All @@ -68,23 +65,30 @@ function menuTemplate (ipc) {
{
label: t('menu-import-configuration'),
click: async function (item, focusedWindow) {
const result = await dialog.showOpenDialog(
{
title: t('menu-import-configuration-dialog'),
filters: [
{ name: 'Mapeo Settings', extensions: ['mapeosettings'] }
],
properties: ['openFile']
}
)
const result = await dialog.showOpenDialog({
title: t('menu-import-configuration-dialog'),
filters: [
{ name: 'Mapeo Settings', extensions: ['mapeosettings'] }
],
properties: ['openFile']
})
logger.info('[MENU] Import Configuration', result)
if (result.canceled) return
if (!result.filePaths || !result.filePaths.length) return
userConfig.importSettings(result.filePaths[0], (err) => {
userConfig.importSettings(result.filePaths[0], err => {
if (err) return onerror(err)
ipc.send('reload-config', (err) => {
if (err) logger.error(err)
logger.debug('[SYSTEM] Forcing window refresh')
ipc.send('reload-config', async err => {
if (err) {
logger.error(err)
logger.debug('[SYSTEM] Forcing window refresh')
focusedWindow.webContents.send('force-refresh-window')
return
}
const data = userConfig.getSettings('metadata')
await dialog.showMessageBox({
message: t('menu-config-complete') + data.name,
buttons: [t('button-submit')]
})
focusedWindow.webContents.send('force-refresh-window')
})
})
Expand All @@ -101,16 +105,14 @@ function menuTemplate (ipc) {
label: t('menu-import-data'),
click: async function (item, focusedWindow) {
// TODO: handle multiple files
const result = await dialog.showOpenDialog(
{
title: t('menu-import-data-dialog'),
filters: [
{ name: 'GeoJSON', extensions: ['geojson'] },
{ name: 'Shape', extensions: ['shp'] }
],
properties: ['openFile']
}
)
const result = await dialog.showOpenDialog({
title: t('menu-import-data-dialog'),
filters: [
{ name: 'GeoJSON', extensions: ['geojson'] },
{ name: 'Shape', extensions: ['shp'] }
],
properties: ['openFile']
})

if (result.canceled) return
if (!result.filePaths || !result.filePaths.length) return
Expand Down Expand Up @@ -266,7 +268,7 @@ function menuTemplate (ipc) {
type: 'checkbox',
checked: updater.channel === 'beta',
click: function (item, focusedWindow) {
updater.channel = (updater.channel === 'beta') ? 'latest' : 'beta'
updater.channel = updater.channel === 'beta' ? 'latest' : 'beta'
updater.checkForUpdates(onUpdate)
},
visible: true
Expand Down Expand Up @@ -294,12 +296,14 @@ function menuTemplate (ipc) {
dialog.showErrorBox(t('menu-status-error-known') + ': ' + err)
} else {
logger.info('[DATABASE STATUS]', feeds)
var incomplete = feeds.filter((s) => s.sofar < s.total)
var incomplete = feeds.filter(s => s.sofar < s.total)
var message
// TODO: make this display more nicely
if (!incomplete.length) message = t('menu-status-complete')
else {
var display = incomplete.map(d => `${d.id.substr(0, 7)}\n${d.sofar}/${d.total}`).join('\n\n')
var display = incomplete
.map(d => `${d.id.substr(0, 7)}\n${d.sofar}/${d.total}`)
.join('\n\n')
message = t('menu-status-incomplete') + '\n\n' + display
}

Expand All @@ -314,7 +318,9 @@ function menuTemplate (ipc) {
{
label: t('menu-report'),
click: function (item, focusedWindow) {
shell.openExternal(`${config.GITHUB_URL}/issues/new?template=bug_report.md`)
shell.openExternal(
`${config.GITHUB_URL}/issues/new?template=bug_report.md`
)
}
}
]
Expand Down

0 comments on commit 24fba77

Please sign in to comment.