Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
SENTRY_DSN='https://XXXX.ingest.sentry.io/00000000'
GA_UACODE=UA-XXXXXXXXXX
# DEBUG=universal-analytics
GA_UACODE=UA-XXXXXXXXX-X
# DEBUG=universal-analytics # do not use DEBUG, because `debug` package will override this var.
# But dotenv-webpack plugin will replace it by string and parse by Terser will fail.
# NODE_DEBUG=request # debug requests in analytics
# DEBUG_PROD=true
18 changes: 14 additions & 4 deletions .erb/configs/webpack.config.main.prod.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import baseConfig from './webpack.config.base';
import CheckNodeEnv from '../scripts/CheckNodeEnv';
import DeleteSourceMaps from '../scripts/DeleteSourceMaps';
import Dotenv from 'dotenv-webpack';

CheckNodeEnv('production');
DeleteSourceMaps();

const devtoolsConfig = process.env.DEBUG_PROD === 'true' ? {
devtool: 'source-map'
} : {};
const devtoolsConfig =
process.env.DEBUG_PROD === 'true'
? {
devtool: 'source-map',
}
: {};

export default merge(baseConfig, {
...devtoolsConfig,

mode: 'production',
// devtool: 'source-map',

target: 'electron-main',

Expand All @@ -37,7 +42,7 @@ export default merge(baseConfig, {
new TerserPlugin({
parallel: true,
}),
]
],
},

plugins: [
Expand All @@ -61,6 +66,11 @@ export default merge(baseConfig, {
DEBUG_PROD: false,
START_MINIMIZED: false,
}),

new Dotenv({
path: path.join(__dirname, '../../.env'),
systemvars: true,
}),
],

/**
Expand Down
6 changes: 6 additions & 0 deletions .erb/configs/webpack.config.renderer.dev.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import webpack from 'webpack';
import chalk from 'chalk';
import { merge } from 'webpack-merge';
import { spawn, execSync } from 'child_process';
import Dotenv from 'dotenv-webpack';
import baseConfig from './webpack.config.base';
import CheckNodeEnv from '../scripts/CheckNodeEnv';
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
Expand Down Expand Up @@ -257,6 +258,11 @@ export default merge(baseConfig, {
NODE_ENV: 'development',
}),

new Dotenv({
path: path.join(__dirname, '../../.env'),
systemvars: true,
}),

new webpack.LoaderOptionsPlugin({
debug: true,
}),
Expand Down
6 changes: 6 additions & 0 deletions .erb/configs/webpack.config.renderer.dev.dll.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import webpack from 'webpack';
import path from 'path';
import { merge } from 'webpack-merge';
import Dotenv from 'dotenv-webpack';
import baseConfig from './webpack.config.base';
import { dependencies } from '../../package.json';
import CheckNodeEnv from '../scripts/CheckNodeEnv';
Expand Down Expand Up @@ -59,6 +60,11 @@ export default merge(baseConfig, {
NODE_ENV: 'development',
}),

new Dotenv({
path: path.join(__dirname, '../../.env'),
systemvars: true,
}),

new webpack.LoaderOptionsPlugin({
debug: true,
options: {
Expand Down
6 changes: 6 additions & 0 deletions .erb/configs/webpack.config.renderer.prod.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import { merge } from 'webpack-merge';
import TerserPlugin from 'terser-webpack-plugin';
import Dotenv from 'dotenv-webpack';
import baseConfig from './webpack.config.base';
import CheckNodeEnv from '../scripts/CheckNodeEnv';
import DeleteSourceMaps from '../scripts/DeleteSourceMaps';
Expand Down Expand Up @@ -170,6 +171,11 @@ export default merge(baseConfig, {
DEBUG_PROD: false,
}),

new Dotenv({
path: path.join(__dirname, '../../.env'),
systemvars: true,
}),

new MiniCssExtractPlugin({
filename: 'style.css',
}),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
"css-loader": "^5.0.1",
"css-minimizer-webpack-plugin": "^2.0.0",
"detect-port": "^1.3.0",
"dotenv-webpack": "^7.0.3",
"electron": "^12.0.2",
"electron-builder": "^22.11.1",
"electron-devtools-installer": "git+https://github.com/MarshallOfSound/electron-devtools-installer.git",
Expand Down Expand Up @@ -204,7 +205,6 @@
"caniuse-lite": "1.0.30001214",
"clsx": "^1.1.1",
"date-fns": "2.20.1",
"dotenv": "10.0.0",
"electron-debug": "^3.1.0",
"electron-log": "^4.2.4",
"electron-updater": "^4.3.4",
Expand Down
7 changes: 5 additions & 2 deletions src/base/repositories/AbstractFileRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const path = require('path');
import FsHelper from '../../helpers/FsHelper';
import PromiseQueue from '../../helpers/PromiseQueueHellper';

const APP_DIR = 'YadroTimeTracker';
const APP_DIR =
process.env.NODE_ENV === 'development'
? 'YadroTimeTracker_test'
: 'YadroTimeTracker';

export default abstract class AbstractFileRepository<T = any> {
dirWithProfileData: string = 'profile1';
Expand Down Expand Up @@ -39,7 +42,7 @@ export default abstract class AbstractFileRepository<T = any> {
}

public restore(defaultValue: T): T {
console.log(`${this.logPrefix} restore`);
console.log(`${this.logPrefix} restore ${this.filePath}`);
if (fs.existsSync(this.filePath)) {
const data = fs.readFileSync(this.filePath, { encoding: 'utf-8' });
// TODO handle parse error. Backup file with issues and return defaultValue
Expand Down
13 changes: 13 additions & 0 deletions src/components/SettingsModal/SettingsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useCallback, useState } from 'react';
import {
Button,
Checkbox,
Divider,
Form,
Expand All @@ -11,6 +12,7 @@ import {
import { CheckboxChangeEvent } from 'antd/lib/checkbox';
import { SaveOutlined } from '@ant-design/icons';
import { observer } from 'mobx-react';
import * as Sentry from '@sentry/browser';
// eslint-disable-next-line import/named
import moment, { Moment } from 'moment';

Expand Down Expand Up @@ -117,6 +119,17 @@ const SettingsModal: React.VFC<ISettingsModalProps> = observer(
onChange={handleChangeNotifications}
/>
</Form.Item>
{process.env.DEBUG_PROD === 'true' && (
<Button
onClick={() => {
const message = `${process.env.NODE_ENV} exception ${Date.now()}`;
Sentry.captureException(new Error(message));
console.log('Sentry.captureException', message);
}}
>
Test Sentry
</Button>
)}
</Modal>
);
}
Expand Down
19 changes: 11 additions & 8 deletions src/hooks/TaskHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { calcDuration, calcDurationGaps, msToTime } from '../helpers/DateTime';
import TaskModel, { ITimeRangeModel } from '../modules/tasks/models/TaskModel';
import TaskTimeItemModel from '../modules/tasks/models/TaskTimeItemModel';

export function useTaskDuration(model: TaskModel | undefined) {
export function useTaskDuration(model?: TaskModel, showZero?: boolean) {
const intervalRef = useRef<NodeJS.Timeout>();
const [duration, setDuration] = useState<string>('');

Expand All @@ -14,9 +14,12 @@ export function useTaskDuration(model: TaskModel | undefined) {
return;
}
const duration = model.duration;
if (duration !== 0) {
setDuration(msToTime(duration, model.active));
}

const durationMs =
duration !== 0 || showZero ? msToTime(duration, model.active) : '';

setDuration(durationMs);

if (model.active) {
intervalRef.current = setInterval(() => {
setDuration(msToTime(model?.duration || 0));
Expand All @@ -39,12 +42,12 @@ export function useTimeItemsDuration(taskTime: TaskTimeItemModel[]) {

const calcTaskDuration = useCallback(
() => calcDuration(taskTime.map((t) => t.time)),
[taskTime],
[taskTime]
);

const calcTaskGapsDuration = useCallback(
() => calcDurationGaps(taskTime.map((t) => t.time)),
[taskTime],
[taskTime]
);

const setTimes = useCallback(() => {
Expand Down Expand Up @@ -78,7 +81,7 @@ export function useTimeRangeDuration(timeRange: ITimeRangeModel | undefined) {

const calcTimeRangeDuration = useCallback(
() => msToTime(timeRange ? calcDuration([timeRange]) : 0),
[timeRange],
[timeRange]
);

useEffect(() => {
Expand All @@ -104,7 +107,7 @@ export function useTimeRangeDuration(timeRange: ITimeRangeModel | undefined) {
}

export function useStartWorkingTime(
timeItems: TaskTimeItemModel[],
timeItems: TaskTimeItemModel[]
): Date | undefined {
return useMemo(() => {
let minTime: Date | undefined;
Expand Down
6 changes: 2 additions & 4 deletions src/main.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@
* When running `yarn build` or `yarn build:main`, this file is compiled to
* `./src/main.prod.js` using webpack. This gives us some performance wins.
*/
import log from 'electron-log';
Object.assign(console, log.functions);
import 'core-js/stable';
import 'regenerator-runtime/runtime';
import dotenv from 'dotenv';
import path from 'path';
import { app, BrowserWindow, shell } from 'electron';
import { autoUpdater } from 'electron-updater';
import log from 'electron-log';
import Badge from 'electron-windows-badge';

import MenuBuilder from './menu';
import { initSentry } from './shared/initSentry';

dotenv.config();

initSentry();

console.log('Working path:', app.getAppPath());
Expand Down
5 changes: 3 additions & 2 deletions src/modules/tasks/TaskStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ export default class TaskStore {
}

deleteTime(task: TaskModel, timeIndex: number) {
if (!task.time[timeIndex].end) {
task.stop();
if (task.active) {
this.stopTimer();
}

task.time.splice(timeIndex, 1);
this.tasksService.save(this.tasks);
GaService.event(EEventCategory.TimeRange, ETimeRangeEvents.Delete);
Expand Down
2 changes: 1 addition & 1 deletion src/screens/dashboard/components/HoursWithDuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Card } from 'antd';
import { createUseStyles } from 'react-jss';

import TaskWithDurationModel from '../../../models/TaskWithDurationModel';
import TaskWithDurationModel from '../../../modules/tasks/models/TaskWithDurationModel';
import { msToTime } from '../../../helpers/DateTime';

interface IHoursWithDurationProps {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/hours/components/HoursCard/HoursCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import format from 'date-fns/format';
import { observer } from 'mobx-react';
import { createUseStyles } from 'react-jss';

import TaskTimeItemModel from '../../../../models/TaskTimeItemModel';
import TaskTimeItemModel from '../../../../modules/tasks/models/TaskTimeItemModel';
import PlayStopButton from '../../../../components/PlayStopButton/PlayStopButton';
import rootStore from '../../../../modules/RootStore';
import { msToTime } from '../../../../helpers/DateTime';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface DurationProps {

export default observer(function Duration({ task }: DurationProps) {
const classes = useStyle();
const duration = TaskHooks.useTaskDuration(task);
const duration = TaskHooks.useTaskDuration(task, true);

return (
<div className={classes.root}>
Expand Down
4 changes: 2 additions & 2 deletions src/services/gaService/GaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const executeOnCondition = (fn: () => void) => {

const GaService = {
pageView(path: string) {
executeOnCondition(analytics?.pageview(path).send());
executeOnCondition(() => analytics?.pageview(path).send());
},
event(category: string, action: string) {
executeOnCondition(analytics?.event(category, action).send());
executeOnCondition(() => analytics?.event(category, action).send());
},
};

Expand Down
4 changes: 4 additions & 0 deletions src/shared/initSentry.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import log from 'electron-log';
Object.assign(console, log.functions);

const Sentry =
process.type === 'browser'
? require('@sentry/electron/dist/main')
Expand All @@ -8,5 +11,6 @@ export function initSentry() {
Sentry.init({
dsn: process.env.SENTRY_DSN,
});
console.log(`[process.type=${process.type}] Sentry.init succeeded`);
}
}
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3931,11 +3931,25 @@ dot-prop@^5.2.0:
dependencies:
is-obj "^2.0.0"

dotenv-defaults@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/dotenv-defaults/-/dotenv-defaults-2.0.2.tgz#6b3ec2e4319aafb70940abda72d3856770ee77ac"
integrity sha512-iOIzovWfsUHU91L5i8bJce3NYK5JXeAwH50Jh6+ARUdLiiGlYWfGw6UkzsYqaXZH/hjE/eCd/PlfM/qqyK0AMg==
dependencies:
dotenv "^8.2.0"

dotenv-expand@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/dotenv-expand/-/dotenv-expand-5.1.0.tgz#3fbaf020bfd794884072ea26b1e9791d45a629f0"
integrity sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==

dotenv-webpack@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/dotenv-webpack/-/dotenv-webpack-7.0.3.tgz#f50ec3c7083a69ec6076e110566720003b7b107b"
integrity sha512-O0O9pOEwrk+n1zzR3T2uuXRlw64QxHSPeNN1GaiNBloQFNaCUL9V8jxSVz4jlXXFP/CIqK8YecWf8BAvsSgMjw==
dependencies:
dotenv-defaults "^2.0.2"

dotenv@10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
Expand Down