<commit_before>'use strict'

const electron = require('electron')
const BrowserWindow = electron.BrowserWindow
const TerminalWindow = require('electron-terminal-window')

const Grid = require('grid')
const uuid = require('uuid')

let grids = []

function testWindow (bounds) {
  const ipcMain = electron.ipcMain
  return new Promise((resolve, reject) => {
    const eventId = uuid.v4()
    const win = new BrowserWindow({
      y: bounds.y,
      x: bounds.x,
      frame: false
    })
    win.loadURL(`file://${__dirname}/index.html`)
    win.maximize()
    const changedBounds = win.getContentBounds()
    ipcMain.once(eventId, (e, winSize) => {
      win.close()
      resolve(Object.assign({}, winSize, {x: changedBounds.x, y: changedBounds.y}))
    })
    setTimeout(() => win.webContents.executeJavaScript(`
      var ipcRenderer = require('electron').ipcRenderer
      ipcRenderer.send('${eventId}', {width: window.innerWidth, height: window.innerHeight})
    `), 500)
  })
  .catch(e => console.error('e:', e))
}

function findBars (bounds, workArea) {
  if (workArea.y > bounds.y) {
    return ({
      id: 'topBar',
      width: workArea.width,
      height: workArea.y - bounds.y,
      x: 0,
      y: 0
    })
  }
  if (bounds.y - workArea.y + bounds.height - workArea.height > 0) {
    return ({
      id: 'bottomBar',
      width: workArea.width,
      height: bounds.y - workArea.y + bounds.height - workArea.height,
      y: workArea.y,
      x: 0
    })
  }
  if (workArea.x > bounds.x) {
    return ({
      id: 'leftBar',
      width: workArea.x - bounds.x,
      height: workArea.height,
      x: 0,
      y: 0
    })
  }
  if (bounds.x - workArea.x + bounds.width - workArea.width > 0) {
    return ({
      id: 'rightBar',
      width: bounds.x - workArea.x + bounds.width - workArea.width,
      height: workArea.height,
      x: workArea.x + workArea.width,
      y: 0
    })
  }
}

function detectPanel (bounds) {
  const screen = electron.screen
  const displays = screen.getAllDisplays()
  return testWindow(bounds)
  .then((workArea) => findBars(bounds, workArea))
  .catch(e => console.error(e))
}

function getGrid (winId) {
  if (winId === undefined) {
    winId = BrowserWindow.getFocusedWindow()
    if (winId === null) return false
  }
  const gridIndex = Object.keys(grids)
    .filter(gridId => {
      const grid = grids[gridId]
      return grid.panes.some(p => {
        return p.wrapped.id === winId
      })
    })[0]
  return grids[gridIndex || 0]
}

function getPane (winId) {<commit_msg>fix: taskbar position<commit_after>'use strict'

const electron = require('electron')
const BrowserWindow = electron.BrowserWindow
const TerminalWindow = require('electron-terminal-window')

const Grid = require('grid')
const uuid = require('uuid')

let grids = []

function testWindow (bounds) {
  const ipcMain = electron.ipcMain
  return new Promise((resolve, reject) => {
    const eventId = uuid.v4()
    const win = new BrowserWindow({
      y: bounds.y,
      x: bounds.x,
      frame: false
    })
    win.loadURL(`file://${__dirname}/index.html`)
    win.maximize()
    const changedBounds = win.getContentBounds()
    ipcMain.once(eventId, (e, winSize) => {
      win.close()
      resolve(Object.assign({}, winSize, {x: changedBounds.x, y: changedBounds.y}))
    })
    setTimeout(() => win.webContents.executeJavaScript(`
      var ipcRenderer = require('electron').ipcRenderer
      ipcRenderer.send('${eventId}', {width: window.innerWidth, height: window.innerHeight})
    `), 500)
  })
  .catch(e => console.error('e:', e))
}

function findBars (bounds, workArea) {
  if (workArea.y > bounds.y) {
    return ({
      id: 'topBar',
      width: workArea.width,
      height: workArea.y - bounds.y,
      x: 0,
      y: 0
    })
  }
  if (bounds.y - workArea.y + bounds.height - workArea.height > 0) {
    return ({
      id: 'bottomBar',
      width: workArea.width,
      height: bounds.height - workArea.height,
      y: workArea.height,
      x: 0
    })
  }
  if (workArea.x > bounds.x) {
    return ({
      id: 'leftBar',
      width: workArea.x - bounds.x,
      height: workArea.height,
      x: 0,
      y: 0
    })
  }
  if (bounds.x - workArea.x + bounds.width - workArea.width > 0) {
    return ({
      id: 'rightBar',
      width: bounds.x - workArea.x + bounds.width - workArea.width,
      height: workArea.height,
      x: workArea.width,
      y: 0
    })
  }
}

function detectPanel (bounds) {
  const screen = electron.screen
  const displays = screen.getAllDisplays()
  return testWindow(bounds)
  .then((workArea) => findBars(bounds, workArea))
  .catch(e => console.error(e))
}

function getGrid (winId) {
  if (winId === undefined) {
    winId = BrowserWindow.getFocusedWindow()
    if (winId === null) return false
  }
  const gridIndex = Object.keys(grids)
    .filter(gridId => {
      const grid = grids[gridId]
      return grid.panes.some(p => {
        return p.wrapped.id === winId
      })
    })[0]
  return grids[gridIndex || 0]
}

function getPane (winId) {
{'fraction_non_alphanumeric': 0.14867010718539103, 'fraction_numerical': 0.0055577610162763, 'mean_word_length': 2.7078734363502575, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '6234107', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1690, 'n_words': 387}