Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Commit

Permalink
Added full raygun support
Browse files Browse the repository at this point in the history
Bumped version to 0.11.0-beta
  • Loading branch information
Guan Gui committed May 3, 2018
1 parent 3f7fbea commit 503169b
Show file tree
Hide file tree
Showing 8 changed files with 498 additions and 83 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.yml
Expand Up @@ -69,6 +69,8 @@ rules:
flowtype/no-types-missing-file-annotation: off
flowtype/generic-spacing: off
arrow-parens: off
no-lone-blocks: off
no-multi-assign: off
plugins: [react, import, flowtype]
settings:
import/resolver:
Expand Down
30 changes: 30 additions & 0 deletions flow-typed/global.js
@@ -0,0 +1,30 @@
/**
* @Author: guiguan
* @Date: 2017-10-02T13:50:52+11:00
* @Last modified by: guiguan
* @Last modified time: 2018-05-02T17:34:06+10:00
*
* dbKoda - a modern, open source code editor, for MongoDB.
* Copyright (C) 2017-2018 Southbank Software
*
* This file is part of dbKoda.
*
* dbKoda is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* dbKoda is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with dbKoda. If not, see <http://www.gnu.org/licenses/>.
*/

/* eslint-disable */

declare var l: Function;
declare var logger: Function;
declare var IS_PRODUCTION: boolean;
12 changes: 9 additions & 3 deletions package.json
Expand Up @@ -4,14 +4,15 @@
"fullName": "dbKoda",
"productName": "dbKoda",
"description": "Next generation MongoDB IDE",
"version": "0.10.1",
"version": "0.11.0-beta",
"author": {
"name": "Southbank Software",
"email": "developer@southbanksoftware.com",
"url": "http://southbanksoftware.com"
},
"main": "lib/",
"keywords": ["dbkoda", "mongodb", "shell", "nosql", "dba", "electron", "react"],
"apiKey": "RnIX59L6lPiNIaTyoY4cEQ==",
"engines": {
"node": ">= 8.9.1"
},
Expand Down Expand Up @@ -45,12 +46,14 @@
"yarn run dist:basic --config electron-builder-release.json --win --x64 --ia32 --publish always",
"postinstall": "yarn run cbuild",
"byo": "MODE=byo yarn run dev",
"byo:debug": "MODE=byo yarn run dev:debug",
"byo:win": "set MODE=byo&& yarn run dev",
"super":
"concurrently --kill-others \"(cd ../dbkoda-ui/; yarn dev)\" \"MODE=super_dev yarn run dev\"",
"mac:gainKeychainAccess":
"security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $KEYCHAIN_PWD ~/Library/Keychains/login.keychain-db > /dev/null",
"dev": "yarn run cbuild:dev && yarn start",
"dev:debug": "yarn run cbuild:dev && yarn debug",
"dev:install": "yarn install --ignore-scripts",
"dev:rebuild:electron":
"ELECTRON_BUILDER_ALLOW_UNRESOLVED_DEPENDENCIES=true electron-builder install-app-deps",
Expand All @@ -69,6 +72,7 @@
"rimraf src/tests/tree/actions/uiDefinitions && mkdir -p src/tests/tree/actions/uiDefinitions && ln -s ../../../../../../dbkoda-ui/src/components/TreeActionPanel/DialogDefinitions src/tests/tree/actions/uiDefinitions/ddd && ln -s ../../../../../../dbkoda-ui/src/components/TreeActionPanel/tests src/tests/tree/actions/uiDefinitions/inputAndTest",
"dev:link:win": "call links.cmd",
"start": "electron .",
"debug": "electron --inspect-brk=9222 .",
"clean": "rimraf lib",
"build": "babel --ignore tests -d lib/ src/",
"cbuild": "yarn run clean && yarn run build",
Expand Down Expand Up @@ -132,13 +136,15 @@
"lodash": "^4.17.5",
"moment": "^2.20.1",
"path": "^0.12.7",
"pkginfo": "^0.4.1",
"portscanner": "^2.1.1",
"raygun": "^0.9.1",
"request-promise-native": "^1.0.5",
"shelljs": "^0.8.1",
"tar": "^4.4.0",
"wget-improved": "^1.5.0",
"winston": "github:guiguan/winston",
"winston-daily-rotate-file": "^2.0.0-rc.6"
"winston": "^3.0.0-rc5",
"winston-daily-rotate-file": "^3.1.3"
},
"devDependencies": {
"babel-cli": "^6.24.1",
Expand Down
94 changes: 68 additions & 26 deletions src/app.js
@@ -1,6 +1,6 @@
/**
* @Last modified by: guiguan
* @Last modified time: 2018-04-24T16:07:36+10:00
* @Last modified time: 2018-05-03T21:37:58+10:00
*
* dbKoda - a modern, open source code editor, for MongoDB.
* Copyright (C) 2017-2018 Southbank Software
Expand Down Expand Up @@ -31,7 +31,19 @@ import { ipcMain } from 'electron';
import portscanner from 'portscanner';
import { createLogger, format, transports, addColors } from 'winston';
import 'winston-daily-rotate-file';
import { levelConfig, commonFormatter, printfFormatter } from '~/helpers/winston';
import {
levelConfig,
commonFormatter,
printfFormatter,
bindDbKodaLoggingApi
} from '~/helpers/winston';
import {
initRaygun,
RaygunTransport,
toggleRaygun,
setUser,
setExitOnUnhandledError
} from '~/helpers/raygun';
import { downloadDrill, downloadDrillController } from './components/drill';
import { initPerformanceBroker, destroyPerformanceBroker } from './components/performance';
import { identifyWorkingMode, invokeApi } from './helpers';
Expand Down Expand Up @@ -90,6 +102,7 @@ global.PATHS = (() => {
};
})();

// TODO can we remove this?
app.commandLine.appendSwitch('disable-renderer-backgrounding');

// TODO create an uninstaller
Expand All @@ -101,14 +114,13 @@ try {
console.log(err);
}

const configWinstonLogger = () => {
global.l = createLogger({
format: format.combine(
format.splat(),
commonFormatter,
format.colorize({ all: true }),
printfFormatter
),
// `raygun` should always be inited
initRaygun(path.resolve(global.PATHS.home, 'raygunCache/dbkoda/'), ['dbkoda']);

// config winston
{
global.logger = global.l = createLogger({
format: format.combine(commonFormatter, format.colorize({ all: true }), printfFormatter),
level: global.IS_PRODUCTION ? 'info' : 'debug',
levels: levelConfig.levels,
transports: [
Expand All @@ -118,31 +130,25 @@ const configWinstonLogger = () => {
datePattern: 'YYYY-MM-DD',
maxSize: '1m',
maxFiles: global.IS_PRODUCTION ? '30d' : '3d'
}),
new RaygunTransport({
handleExceptions: true
})
]
],
exitOnError: false
});

addColors(levelConfig);

process.on('unhandledRejection', reason => {
l.error(reason);
});
bindDbKodaLoggingApi(l);

process.on('uncaughtException', err => {
l.error(err.stack);
});
};
configWinstonLogger();
// NOTE: after this point, every error (unhandled, l.error, console.error) should be reported to
// `raygun`
}

global.findAvailablePort = portscanner.findAPortNotInUse;

l.notice(`Starting up with ${modeDescription} mode...`);
l.info(`isUAT:: ${process.env.UAT} :: ${global.UAT}`);
l.info(
`Global Paths::${global.PATHS.configPath} , ${global.PATHS.profilesPath} , ${
global.PATHS.stateStore
}`
);

let controllerPortPromise;

Expand Down Expand Up @@ -403,7 +409,12 @@ const createMainWindow = () => {
};

const handleRendererLog = (_event, level, message) => {
l[level](`Window ${mainWindow.getTitle()}: ${message}`);
if (level === 'error') {
// don't forward ui errors to raygun via main process (dbkoda)
l._error(`Window ${mainWindow.getTitle()}: ${message}`);
} else {
l[level](`Window ${mainWindow.getTitle()}: ${message}`);
}
};

const handleAppReady = () => {
Expand Down Expand Up @@ -476,13 +487,43 @@ const createMainWindow = () => {
}
};

// NOTE: global.config is ready only all time
const handleConfigLoaded = (_event, config) => {
global.config = config;

setExitOnUnhandledError(false);

setUser(_.get(global.config, 'user'));
// BUG: it has to be toggled off first, then it can toggle freely; otherwise, toggle on will
// throw an exception
toggleRaygun(false);
toggleRaygun(_.get(global.config, 'telemetryEnabled'));
};

const handleConfigChanged = (_event, changed) => {
_.forEach(changed, (v, k) => {
_.set(global.config, k, v.new);
});

if (_.has(changed, 'user.id')) {
setUser(_.get(global.config, 'user'));
}

if (_.has(changed, 'telemetryEnabled')) {
toggleRaygun(_.get(global.config, 'telemetryEnabled'));
}
};

// TODO needs to assign each event a windows id if we are going to support multiple windows
ipcMain.once('appReady', handleAppReady);
ipcMain.once('appCrashed', handleAppCrashed);

ipcMain.on('drill', handleDrillRequest);
ipcMain.on('log', handleRendererLog);

ipcMain.on('configLoaded', handleConfigLoaded);
ipcMain.on('configChanged', handleConfigChanged);

initPerformanceBroker();

mainWindow.on('closed', () => {
Expand Down Expand Up @@ -899,5 +940,6 @@ app.on('window-all-closed', () => {

app.on('will-quit', () => {
l.notice('Shutting down...');
setExitOnUnhandledError(true);
quitController();
});
30 changes: 30 additions & 0 deletions src/helpers/pkginfo.js
@@ -0,0 +1,30 @@
/**
* @flow
*
* @Author: Guan Gui <guiguan>
* @Date: 2018-04-27T11:25:23+10:00
* @Email: root@guiguan.net
* @Last modified by: guiguan
* @Last modified time: 2018-04-27T11:27:26+10:00
*
* dbKoda - a modern, open source code editor, for MongoDB.
* Copyright (C) 2017-2018 Southbank Software
*
* This file is part of dbKoda.
*
* dbKoda is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* dbKoda is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with dbKoda. If not, see <http://www.gnu.org/licenses/>.
*/

// $FlowFixMe
require('pkginfo')(module, 'version', 'apiKey');

0 comments on commit 503169b

Please sign in to comment.