<commit_before>/* @flow */

import type { Store } from 'redux';
import type { AppState } from './records';
import { ipcRenderer } from 'electron';
import { getVCardWindow } from './vcard';
import { extname } from 'path';
import { importFileIntoNotebook } from './actions';

import {
  forceShutdownKernel,
} from './kernel/shutdown';

export function unload(store: Store<AppState, Action>) {
  const state = store.getState();
  const kernel = {
    channels: state.app.channels,
    spawn: state.app.spawn,
    connectionFile: state.app.connectionFile,
  };
  forceShutdownKernel(kernel);
}

export function initGlobalHandlers(store: Store<AppState, Action>) {
  global.window.onunload = unload.bind(null, store);
  // via org.analogmachine.tellurium protocol
  ipcRenderer.on('update-personal-info', (e, keys) => {
    const vcard = getVCardWindow();
    if (vcard) {
      vcard.webContents.send('update-personal-info', keys);
    }
  });

  // https://gist.github.com/armaldio/75ae2b6476da83110cf8d54d47e89b56

  document.addEventListener('drop', (e) => {
      e.preventDefault();
      e.stopPropagation();
      for (let f of e.dataTransfer.files) {
          const ext = extname(f.path);
          if (ext === '.omex' || ext === '.zip') {
            store.dispatch(importFileIntoNotebook('', f.path, '', 'omex', 'below'));
          } else if (ext === '.xml') {
            store.dispatch(importFileIntoNotebook('', f.path, '', 'sbml', 'below'));
          }
      }
      return false;
  });

  document.addEventListener('dragover', (e) => {
      e.preventDefault();
      e.stopPropagation();
  });
}<commit_msg>add d&d support for python scripts, fix #10<commit_after>/* @flow */

import type { Store } from 'redux';
import type { AppState } from './records';
import { ipcRenderer } from 'electron';
import { getVCardWindow } from './vcard';
import { extname } from 'path';
import { importFileIntoNotebook } from './actions';

import {
  forceShutdownKernel,
} from './kernel/shutdown';

export function unload(store: Store<AppState, Action>) {
  const state = store.getState();
  const kernel = {
    channels: state.app.channels,
    spawn: state.app.spawn,
    connectionFile: state.app.connectionFile,
  };
  forceShutdownKernel(kernel);
}

export function initGlobalHandlers(store: Store<AppState, Action>) {
  global.window.onunload = unload.bind(null, store);
  // via org.analogmachine.tellurium protocol
  ipcRenderer.on('update-personal-info', (e, keys) => {
    const vcard = getVCardWindow();
    if (vcard) {
      vcard.webContents.send('update-personal-info', keys);
    }
  });

  // https://gist.github.com/armaldio/75ae2b6476da83110cf8d54d47e89b56

  document.addEventListener('drop', (e) => {
      e.preventDefault();
      e.stopPropagation();
      for (let f of e.dataTransfer.files) {
        const ext = extname(f.path);
        if (ext === '.omex' || ext === '.zip') {
          store.dispatch(importFileIntoNotebook('', f.path, '', 'omex', 'below'));
        } else if (ext === '.xml') {
          store.dispatch(importFileIntoNotebook('', f.path, '', 'sbml', 'below'));
        } else if (ext === '.py') {
          store.dispatch(importFileIntoNotebook('', f.path, '', 'python', 'below'));
        }
      }
      return false;
  });

  document.addEventListener('dragover', (e) => {
    e.preventDefault();
    e.stopPropagation();
  });
}
{'fraction_non_alphanumeric': 0.16799763383614316, 'fraction_numerical': 0.013013901212658977, 'mean_word_length': 3.275600505689001, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3195986', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1079, 'n_words': 227}