Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix: flow issues

Ilian Sapundshievf85292e5f493
diff --git a/app/index.js b/app/index.js
index 4c13a8bc6..148225dfb 100644
--- a/app/index.js
+++ b/app/index.js
@@ -30,8 +30,11 @@ const { store, persistor } = configureStore();
document.addEventListener('contextmenu', event => event.preventDefault());
if (process.env.NODE_ENV === 'production') {
+ // $FlowFixMe
console.log = () => {};
+ // $FlowFixMe
console.time = () => {};
+ // $FlowFixMe
console.timeEnd = () => {};
}
diff --git a/app/main.dev.js b/app/main.dev.js
index ed67a11f9..6bb958715 100644
--- a/app/main.dev.js
+++ b/app/main.dev.js
@@ -25,20 +25,24 @@ let mainWindow = null;
global.splashWorkerWindow = null;
if (process.env.NODE_ENV === 'production') {
+ // eslint-disable-next-line
const sourceMapSupport = require('source-map-support');
sourceMapSupport.install();
+ // $FlowFixMe
console.log = () => {};
+ // $FlowFixMe
console.time = () => {};
+ // $FlowFixMe
console.timeEnd = () => {};
}
-let debugMode;
+// let debugMode;
let startupFilePath;
let portableMode;
process.argv.forEach((arg, count) => {
if (arg.toLowerCase() === '-d' || arg.toLowerCase() === '--debug') {
- debugMode = true;
+ // debugMode = true;
} else if (arg.toLowerCase() === '-p' || arg.toLowerCase() === '--portable') {
app.setPath('userData', process.cwd() + '/tsprofile'); // making the app portable
portableMode = true;
@@ -64,8 +68,10 @@ if (
process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true'
) {
+ // eslint-disable-next-line
require('electron-debug')({ showDevTools: false, devToolsMode: 'right' });
const p = path.join(__dirname, '..', 'app', 'node_modules');
+ // eslint-disable-next-line
require('module').globalPaths.push(p);
}
@@ -81,7 +87,7 @@ const installExtensions = async () => {
default: installExtension,
REACT_DEVELOPER_TOOLS,
REDUX_DEVTOOLS
- } = require('electron-devtools-installer');
+ } = require('electron-devtools-installer'); // eslint-disable-line
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
const extensions = [REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS];
@@ -196,6 +202,10 @@ app.on('ready', async () => {
buttons: ['Reload', 'Close']
};
dialog.showMessageBox(mainWindow, options, index => {
+ if (!mainWindow) {
+ globalShortcut.unregisterAll();
+ return;
+ }
mainWindow.hide();
if (index === 0) {
reloadApp();
@@ -233,15 +243,15 @@ app.on('ready', async () => {
});
ipcMain.on('app-data-path-request', event => {
- event.returnValue = app.getPath('appData');
+ event.returnValue = app.getPath('appData'); // eslint-disable-line
});
ipcMain.on('app-version-request', event => {
- event.returnValue = app.getVersion();
+ event.returnValue = app.getVersion(); // eslint-disable-line
});
ipcMain.on('app-dir-path-request', event => {
- event.returnValue = path.join(__dirname, '');
+ event.returnValue = path.join(__dirname, ''); // eslint-disable-line
});
ipcMain.on('global-shortcuts-enabled', (e, globalShortcutsEnabled) => {
@@ -269,7 +279,7 @@ app.on('ready', async () => {
process.on('uncaughtException', error => {
if (error.stack) {
console.error('error:', error.stack);
- throw new Error('error:', error.stack);
+ throw new Error(error.stack);
}
reloadApp();
});
@@ -313,7 +323,7 @@ app.on('ready', async () => {
function reloadApp() {
if (mainWindow) {
- mainWindow.loadURL(indexPath);
+ mainWindow.loadURL(mainHTML);
}
}
});
diff --git a/app/utils/dates.js b/app/utils/dates.js
index 2286caba0..cb8a5f50a 100644
--- a/app/utils/dates.js
+++ b/app/utils/dates.js
@@ -390,25 +390,28 @@ export function parseDate(date: string) {
}
// parse “YYYYmmdd” to 'Fri Jul 15 2016 00:00:00 GMT+0300 (FLE Summer Time)'
-export function parseFullDate(date) {
+export function parseFullDate(date: string) {
// validate year as 4 digits, month as 01-12, and day as 01-31
- if ((date = date.match(/^(\d{4})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])$/))) {
+ const parsedDate = date.match(
+ /^(\d{4})(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])$/
+ );
+ if (parsedDate) {
// make a date
- date[0] = new Date(+date[1], +date[2] - 1, +date[3]);
+ const result = new Date(+parsedDate[1], +parsedDate[2] - 1, +parsedDate[3]);
// check if month stayed the same (ie that day number is valid)
- if (date[0].getMonth() === +date[2] - 1) {
- return date[0];
+ if (result.getMonth() === +parsedDate[2] - 1) {
+ return result;
}
}
}
// return array of [years, month]
-export function parseToDate(date) {
+export function parseToDate(date: string) {
const dateMonth = convertToDate(date);
let d;
if (dateMonth) {
d = dateMonth;
- } else if (dateMonth.length === 5) {
+ } else if (dateMonth && dateMonth.length === 5) {
const dateString = dateMonth.split('-');
d = new Date(dateString[0], dateString[1]);
}
@@ -416,7 +419,7 @@ export function parseToDate(date) {
}
// Format Sun May 11, 2014 to 2014-05
-export function formatDateMonth(date) {
+export function formatDateMonth(date: string) {
const d = new Date(date);
let month = '' + (d.getMonth() + 1);
const year = d.getFullYear();
@@ -428,7 +431,7 @@ export function formatDateMonth(date) {
}
// Format Sun May 11, 2014 to 2014-05-11
-export function formatDate(date) {
+export function formatDate(date: string) {
const d = new Date(date);
let month = '' + (d.getMonth() + 1);
let day = '' + d.getDate();
@@ -446,7 +449,7 @@ export function formatDate(date) {
export function toHHMMSS(time: string): string {
const match = time.match(/(\d{2})(\d{2})(\d{2})/);
- return match[1] + ':' + match[2] + ':' + match[3];
+ return match ? match[1] + ':' + match[2] + ':' + match[3] : '';
}
export function convertToDate(date: string) {