<commit_before>/* eslint global-require: 1, flowtype-errors/show-errors: 0 */

/**
 * This module executes inside of electron's main process. You can start
 * electron renderer process from here and communicate with the other processes
 * through IPC.
 *
 * When running `npm run build` or `npm run build-main`, this file is compiled to
 * `./app/main.prod.js` using webpack. This gives us some performance wins.
 *
 * @flow
 */
import { app, BrowserWindow, protocol, ipcMain, Menu, Tray } from 'electron';
import logger from 'logger';
import { isRunningUnpacked, isRunningPackaged, I18N_CONFIG, PROTOCOLS } from 'appConstants';
import { parse as parseURL } from 'url';
import pkg from 'appPackage';

import * as peruseAppActions from 'actions/peruse_actions';
import * as authenticatorActions from 'actions/authenticator_actions';
import setupBackground from './setupBackground';

import openWindow from './openWindow';
import { loadExtensions }  from './extensions';
import { configureStore } from './store/configureStore';

// TODO: Deprecate this in favour of redux actions
// import handleCommands from './commandHandling';

// TODO: This should be handled in an extensible fashion
import { addTab } from 'actions/tabs_actions';
import { setupServerVars, startServer } from './server';

// import { createSafeInfoWindow, createTray } from './setupTray';

const initialState = {};
let bgProcessWindow = null;

// Add middleware from extensions here.
const loadMiddlewarePackages = [];

const store = configureStore( initialState, loadMiddlewarePackages );


global.mainProcessStore = store;
// renderer error notifications
ipcMain.on( 'errorInWindow', ( event, data ) =>
{
    logger.error( data );
} );

const mainWindow = null;

const handleSafeUrls = ( url ) =>
{
    // added as from renderer it's receiving as a lowercase string. WHY?
    const parsedUrl = parseURL( url );

    // TODO. Queue incase of not started.
    logger.verbose( 'Receiving Open Window Param (a url)', url );

    // TODO:
    // If the received URL protocol is looong and starts with 'safe' it's fair to assume it's the
    // auth response
    // Currently _ONLY_ peruse is going to be making a req.fe
    // When we have more... What then? Are we able to retrieve the url schemes registered for a given app?
    if ( parsedUrl.protocol === 'safe-auth:' )
    {
        store.dispatch( authenticatorActions.handleAuthUrl( url ) );
    }
    if ( parsedUrl.protocol === 'safe:' )
    {
        store.dispatch( addTab( { url, isActiveTab: true } ) );
    }
    // 20 is arbitrarily looong right now...
    else if ( parsedUrl.protocol.startsWith( 'safe-' ) && parsedUrl.protocol.length > 20 )
    {
        store.dispatch( peruseAppActions.receivedAuthResponse( url ) );
    }
};


// Register all schemes from package.json
protocol.registerStandardSchemes( pkg.build.protocols.schemes, { secure: true } );
<commit_msg>fix/open-uri: check for protocol before attempting to parse<commit_after>/* eslint global-require: 1, flowtype-errors/show-errors: 0 */

/**
 * This module executes inside of electron's main process. You can start
 * electron renderer process from here and communicate with the other processes
 * through IPC.
 *
 * When running `npm run build` or `npm run build-main`, this file is compiled to
 * `./app/main.prod.js` using webpack. This gives us some performance wins.
 *
 * @flow
 */
import { app, BrowserWindow, protocol, ipcMain, Menu, Tray } from 'electron';
import logger from 'logger';
import { isRunningUnpacked, isRunningPackaged, I18N_CONFIG, PROTOCOLS } from 'appConstants';
import { parse as parseURL } from 'url';
import pkg from 'appPackage';

import * as peruseAppActions from 'actions/peruse_actions';
import * as authenticatorActions from 'actions/authenticator_actions';
import setupBackground from './setupBackground';

import openWindow from './openWindow';
import { loadExtensions }  from './extensions';
import { configureStore } from './store/configureStore';

// TODO: Deprecate this in favour of redux actions
// import handleCommands from './commandHandling';

// TODO: This should be handled in an extensible fashion
import { addTab } from 'actions/tabs_actions';
import { setupServerVars, startServer } from './server';

// import { createSafeInfoWindow, createTray } from './setupTray';

const initialState = {};
let bgProcessWindow = null;

// Add middleware from extensions here.
const loadMiddlewarePackages = [];

const store = configureStore( initialState, loadMiddlewarePackages );


global.mainProcessStore = store;
// renderer error notifications
ipcMain.on( 'errorInWindow', ( event, data ) =>
{
    logger.error( data );
} );

const mainWindow = null;

const handleSafeUrls = ( url ) =>
{
    // added as from renderer it's receiving as a lowercase string. WHY?
    const parsedUrl = parseURL( url );

    // TODO. Queue incase of not started.
    logger.verbose( 'Receiving Open Window Param (a url)', url );

    // TODO:
    // If the received URL protocol is looong and starts with 'safe' it's fair to assume it's the
    // auth response
    // Currently _ONLY_ peruse is going to be making a req.fe
    // When we have more... What then? Are we able to retrieve the url schemes registered for a given app?
    if ( parsedUrl.protocol === 'safe-auth:' )
    {
        store.dispatch( authenticatorActions.handleAuthUrl( url ) );
    }
    if ( parsedUrl.protocol === 'safe:' )
    {
        store.dispatch( addTab( { url, isActiveTab: true } ) );
    }
    // 20 is arbitrarily looong right now...
    else if ( parsedUrl.protocol && parsedUrl.protocol.startsWith( 'safe-' ) && parsedUrl.protocol.length > 20 )
    {
        store.dispatch( peruseAppActions.receivedAuthResponse( url ) );
    }
};


// Register all schemes from package.json
protocol.registerStandardSchemes( pkg.build.protocols.schemes, { secure: true } );

{'fraction_non_alphanumeric': 0.11103542234332425, 'fraction_numerical': 0.0027247956403269754, 'mean_word_length': 3.6722354813046936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4787221', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1633, 'n_words': 598}