-
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathipc.js
More file actions
171 lines (144 loc) · 4.47 KB
/
Copy pathipc.js
File metadata and controls
171 lines (144 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const { dialog, app, ipcMain } = require('electron')
const updater = require('./auto-updater')
const logger = require('../logger')
const userConfig = require('./user-config')
const i18n = require('./i18n')
/**
* Miscellaneous ipcMain calls that don't hit mapeo-core
*/
module.exports = function (ipcSend) {
function onError (err) {
logger.error('[MAIN/IPC] error', err)
ipcSend('error', err.message, err.stack)
}
updater.on('error', err => {
if (err.message.match(/net*/)) logger.debug(err.message)
else {
logger.error('[UPDATER] error', err)
ipcSend('update-status', 'update-error', err)
}
})
updater.on('update-inactive', () => {
ipcSend('update-status', 'update-inactive')
})
updater.updateDownloaded(updateInfo => {
logger.info('[UPDATER] update-downloaded', updateInfo)
ipcSend('update-status', 'update-downloaded', updateInfo)
})
updater.updateNotAvailable(() => {
logger.info('[UPDATER] update-not-available')
ipcSend('update-status', 'update-not-available', null)
})
updater.downloadProgress(updateInfo => {
logger.info('[UPDATER] update-progress', updateInfo)
/*
{
progress: {
total: 141164463,
delta: 1655048,
transferred: 11384326,
percent: 8.064583506402741,
bytesPerSecond: 2244544
}
}
*/
ipcSend('update-status', 'update-progress', updateInfo)
})
updater.updateAvailable(updateInfo => {
// version, files, path, sha512, releaseDate
logger.info('[UPDATER] update-available', updateInfo)
ipcSend('update-status', 'update-available', updateInfo)
})
ipcMain.on('download-update', function (event) {
updater.downloadUpdate()
})
ipcMain.on('check-for-updates', function (event) {
updater.checkForUpdates()
})
ipcMain.on('quit-and-install', function (event) {
updater.quitAndInstall()
})
ipcMain.on('get-user-data', function (event, type) {
var data = userConfig.getSettings(type)
if (!data) logger.debug('Could not get data for', type)
event.returnValue = data
})
ipcMain.on('error', function (ev, message) {
onError(new Error(message))
})
ipcMain.on('set-locale', function (ev, locale) {
app.translations = i18n.setLocale(locale)
i18n.save()
ipcSend('CLOSING:update-message', i18n.t('closing-screen'))
})
ipcMain.on('get-locale', function (ev) {
ev.returnValue = i18n.locale
})
ipcMain.handle('CLOSING:get-message', function () {
return i18n.t('closing-screen')
})
ipcMain.handle('select-mb-tile-file', async function () {
const result = await dialog.showOpenDialog({
filters: [{ name: 'MbTiles', extensions: ['mbtiles'] }],
properties: ['openFile']
})
return result
})
ipcMain.on('show-error-dialog', function (event, title, content) {
dialog.showErrorBox(title, content)
})
ipcMain.on('save-file', function () {
var metadata = userConfig.getSettings('metadata')
var ext = metadata ? metadata.dataset_id : 'mapeodata'
dialog
.showSaveDialog({
title: i18n.t('save-db-dialog'),
defaultPath: 'database.' + ext,
filters: [
{
name: 'Mapeo Data (*.' + ext + ')',
extensions: ['mapeodata', 'mapeo-jungle', ext]
}
]
})
.then(onOpen)
.catch(onError)
function onOpen ({ filePath, canceled }) {
if (canceled || typeof filePath === 'undefined') return
ipcSend('select-file', filePath)
}
})
ipcMain.on('open-file', function () {
var metadata = userConfig.getSettings('metadata')
var ext = metadata ? metadata.dataset_id : 'mapeodata'
dialog
.showOpenDialog({
title: i18n.t('open-db-dialog'),
properties: ['openFile'],
filters: [
{
name: 'Mapeo Data (*.' + ext + ')',
extensions: ['mapeodata', 'mapeo-jungle', ext, 'sync', 'zip']
}
]
})
.then(onOpen)
.catch(onError)
function onOpen ({ canceled, filePaths }) {
if (canceled || typeof filePaths === 'undefined') return
if (filePaths.length === 1) {
var file = filePaths[0]
ipcSend('select-file', file)
}
}
})
ipcMain.on('zoom-to-latlon-request', function (_, lon, lat) {
ipcSend('zoom-to-latlon-response', [lon, lat])
})
ipcMain.on('force-refresh-window', function () {
ipcSend('force-refresh-window')
})
ipcMain.on('refresh-window', function () {
ipcSend('refresh-window')
})
}