Skip to content

Commit

Permalink
Merge pull request #104 from bitfinexcom/beta
Browse files Browse the repository at this point in the history
Release version 3.5.2
  • Loading branch information
ezewer authored Aug 9, 2021
2 parents 8605a11 + 236a7bd commit 1179a00
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build/linux-launcher/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ appFilePath="$ROOT/app"
logFilePath="$ROOT/error.log"

output=$("$appFilePath" 2>&1)
mess=$(echo "$output" | grep -v WARNING | grep -v electron\/issues\/23506 | grep -v Cannot\ download\ differentially)
mess=$(echo "$output" | grep -v WARNING | grep -v electron\/issues\/23506 | grep -v Cannot\ download\ differentially | grep -v GtkDialog mapped without a transient parent)

if [ "$mess" != "" ]; then
echo $mess>>"$logFilePath"
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bfx-report-electron",
"version": "3.5.1",
"version": "3.5.2",
"repository": "https://github.com/bitfinexcom/bfx-report-electron",
"description": "Reporting tool",
"author": "bitfinex.com",
Expand Down Expand Up @@ -32,7 +32,7 @@
},
"devDependencies": {
"app-builder-bin": "^3.5.13",
"electron": "13.1.6",
"electron": "13.1.7",
"electron-builder": "22.11.7",
"node-gyp": "7.1.2",
"node-pre-gyp": "^0.11.0",
Expand Down Expand Up @@ -63,6 +63,7 @@
"repo": "bfx-report-electron",
"owner": "bitfinexcom",
"channel": "latest",
"allowPrerelease": true,
"useMultipleRangeRequest": false,
"updaterCacheDirName": "bfx-report-electron-updater"
},
Expand Down
38 changes: 33 additions & 5 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,33 @@ let isMigrationsError = false
})
})

ipc.on('message', (mess) => {
const { state } = { ...mess }

if (
state !== 'all-tables-have-been-cleared' &&
state !== 'all-tables-have-not-been-cleared'
) {
return
}

process.send(mess)
})
process.on('message', (mess) => {
const { state } = { ...mess }

if (state !== 'clear-all-tables') {
return
}

ipc.send(mess)
})

const announcePromise = grapes.onAnnounce('rest:report:api')
const ipcReadyPromise = new Promise((resolve, reject) => {
ipc.once('error', reject)

const handler = (mess) => {
const handlerMess = (mess) => {
const { state } = { ...mess }

if (state === 'error:migrations') {
Expand All @@ -149,13 +171,19 @@ let isMigrationsError = false
return
}

ipc.removeListener('error', reject)
ipc.removeListener('message', handler)
ipc.removeListener('error', handlerErr)
ipc.removeListener('message', handlerMess)

resolve()
}

ipc.on('message', handler)
const handlerErr = (err) => {
ipc.removeListener('message', handlerMess)

reject(err)
}

ipc.once('error', handlerErr)
ipc.on('message', handlerMess)
})

await Promise.all([announcePromise, ipcReadyPromise])
Expand Down
4 changes: 4 additions & 0 deletions src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
const CONFIGS_FILE_NAME = 'bfx-report-configs.json'
const DEFAULT_ARCHIVE_DB_FILE_NAME = 'bfx-report-db-archive'
const DB_FILE_NAME = 'db-sqlite_sync_m0.db'
const DB_SHM_FILE_NAME = `${DB_FILE_NAME}-shm`
const DB_WAL_FILE_NAME = `${DB_FILE_NAME}-wal`
const SECRET_KEY_FILE_NAME = 'secret-key'

module.exports = {
CONFIGS_FILE_NAME,
DEFAULT_ARCHIVE_DB_FILE_NAME,
DB_FILE_NAME,
DB_SHM_FILE_NAME,
DB_WAL_FILE_NAME,
SECRET_KEY_FILE_NAME
}
8 changes: 8 additions & 0 deletions src/create-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ module.exports = ({
accelerator: 'CmdOrCtrl+D',
click: removeDB({ pathToUserData })
},
{
label: 'Clear all data',
accelerator: 'CmdOrCtrl+D',
click: removeDB({
pathToUserData,
shouldAllTablesBeCleared: true
})
},
{
label: 'Change reports folder',
accelerator: 'CmdOrCtrl+F',
Expand Down
11 changes: 10 additions & 1 deletion src/export-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const {
const {
DEFAULT_ARCHIVE_DB_FILE_NAME,
DB_FILE_NAME,
DB_SHM_FILE_NAME,
DB_WAL_FILE_NAME,
SECRET_KEY_FILE_NAME
} = require('./const')

Expand All @@ -30,6 +32,8 @@ module.exports = ({
`${DEFAULT_ARCHIVE_DB_FILE_NAME}-${timestamp}.zip`
)
const dbPath = path.join(pathToUserData, DB_FILE_NAME)
const dbShmPath = path.join(pathToUserData, DB_SHM_FILE_NAME)
const dbWalPath = path.join(pathToUserData, DB_WAL_FILE_NAME)
const secretKeyPath = path.join(pathToUserData, SECRET_KEY_FILE_NAME)

return async () => {
Expand Down Expand Up @@ -60,7 +64,12 @@ module.exports = ({
}

await showLoadingWindow()
await zip(filePath, [dbPath, secretKeyPath])
await zip(filePath, [
dbPath,
dbShmPath,
dbWalPath,
secretKeyPath
])
await hideLoadingWindow()

await showMessageModalDialog(win, {
Expand Down
11 changes: 10 additions & 1 deletion src/import-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const relaunch = require('./relaunch')
const { rm } = require('./helpers')
const {
DB_FILE_NAME,
DB_SHM_FILE_NAME,
DB_WAL_FILE_NAME,
SECRET_KEY_FILE_NAME
} = require('./const')

Expand Down Expand Up @@ -78,7 +80,14 @@ module.exports = ({
const extractedfileNames = await unzip(
filePaths[0],
pathToUserData,
{ extractFiles: [DB_FILE_NAME, SECRET_KEY_FILE_NAME] }
{
extractFiles: [
DB_FILE_NAME,
DB_SHM_FILE_NAME,
DB_WAL_FILE_NAME,
SECRET_KEY_FILE_NAME
]
}
)

if (extractedfileNames.every(file => file !== DB_FILE_NAME)) {
Expand Down
8 changes: 7 additions & 1 deletion src/pause-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ const _closeServer = () => {
})
}

module.exports = async () => {
module.exports = async (opts = {}) => {
const {
beforeClosingServHook = () => {}
} = opts

await showLoadingWindow({ isRequiredToCloseAllWins: true })

await beforeClosingServHook()

await _closeServer()
}
18 changes: 17 additions & 1 deletion src/relaunch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@

const electron = require('electron')

const {
isZipRelease
} = require('./auto-updater/utils')

module.exports = () => {
const app = electron.app || electron.remote.app

app.relaunch({ args: process.argv.slice(1).concat(['--relaunch']) })
const options = {
args: process.argv.slice(1).concat(['--relaunch'])
}

if (
process.env.APPIMAGE &&
!isZipRelease()
) {
options.execPath = process.env.APPIMAGE
options.args.unshift('--appimage-extract-and-run')
}

app.relaunch(options)
app.exit(0)
}
72 changes: 66 additions & 6 deletions src/remove-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const electron = require('electron')

const ipcs = require('./ipcs')
const showErrorModalDialog = require('./show-error-modal-dialog')
const showMessageModalDialog = require('./show-message-modal-dialog')
const pauseApp = require('./pause-app')
Expand Down Expand Up @@ -34,30 +35,89 @@ const _rmDb = async (pathToUserData) => {
}
}

module.exports = ({ pathToUserData }) => {
const _clearAllTables = () => {
ipcs.serverIpc.send({
state: 'clear-all-tables'
})

return new Promise((resolve, reject) => {
const handlerMess = (mess) => {
const { state } = { ...mess }

if (
state !== 'all-tables-have-been-cleared' &&
state !== 'all-tables-have-not-been-cleared'
) {
return
}

ipcs.serverIpc.removeListener('error', handlerErr)
ipcs.serverIpc.removeListener('message', handlerMess)

if (state === 'all-tables-have-not-been-cleared') {
reject(new DbRemovingError(state))

return
}

resolve()
}
const handlerErr = (err) => {
ipcs.serverIpc.removeListener('message', handlerMess)

reject(err)
}

ipcs.serverIpc.once('error', handlerErr)
ipcs.serverIpc.on('message', handlerMess)
})
}

module.exports = ({
pathToUserData,
shouldAllTablesBeCleared
}) => {
return async () => {
const win = electron.BrowserWindow.getFocusedWindow()
const title = shouldAllTablesBeCleared
? 'Clear all data'
: 'Remove database'
const message = shouldAllTablesBeCleared
? 'Are you sure you want to clear all data?'
: 'Are you sure you want to remove the database?'

try {
const {
btnId
} = await showMessageModalDialog(win, {
type: 'question',
title: 'Remove database',
message: 'Are you sure you want to remove the database?'
title,
message
})
const isOkBtnPushed = btnId === 1

if (!isOkBtnPushed) {
return
}

await pauseApp()
await _rmDb(pathToUserData)
await pauseApp({
beforeClosingServHook: async () => {
if (!shouldAllTablesBeCleared) {
return
}

await _clearAllTables()
}
})

if (!shouldAllTablesBeCleared) {
await _rmDb(pathToUserData)
}

relaunch()
} catch (err) {
try {
await showErrorModalDialog(win, 'Remove database', err)
await showErrorModalDialog(win, title, err)
} catch (err) {
console.error(err)
}
Expand Down

0 comments on commit 1179a00

Please sign in to comment.