<commit_before>const {BrowserWindow, ipcMain, shell} = require('electron')
const path = require('path')

const ELMSTARTUP = 400

const log = require('../../core-built/app.js').default.logger({
  component: 'windows'
})

module.exports = class WindowManager {
  constructor (app, desktop) {
    this.win = null
    this.app = app
    this.desktop = desktop
    this.log = require('../../core-built/app.js').default.logger({
      component: 'GUI/' + this.windowOptions().title
    })

    let handlers = this.ipcEvents()
    Object.keys(handlers).forEach((name) => {
      if (!handlers[name]) {
        throw new Error('undefined handler for event ' + name)
      }
      ipcMain.on(name, handlers[name].bind(this))
    })
  }

  /* abtract */
  windowOptions () {
    throw new Error('extend WindowManager before using')
  }

  /* abtract */
  ipcEvents () {
    throw new Error('extend WindowManager before using')
  }

  makesAppVisible () {
    return true
  }

  show () {
    if (!this.win) return this.create()
    this.log.debug('show')
    this.win.show()
    return Promise.resolve(this.win)
  }

  hide () {
    if (this.win) {
      this.log.debug('hide')
      this.win.close()
    }
    this.win = null
  }

  shown () {
    return this.win != null
  }

  reload () {
    if (this.win) {
      this.log.debug('reload')
      this.win.reload()
    }
  }

  send (...args) {
    this.win && this.win.webContents && this.win.webContents.send(...args)
  }

  hash () {
    return ''
  }

  create () {
    this.log.debug('create')
    const opts = this.windowOptions()
    opts.show = false
    this.win = new BrowserWindow(opts)

    // openExternalLinks<commit_msg>gui: Fix .focus error (#956)<commit_after>const {BrowserWindow, ipcMain, shell} = require('electron')
const path = require('path')

const ELMSTARTUP = 400

const log = require('../../core-built/app.js').default.logger({
  component: 'windows'
})

module.exports = class WindowManager {
  constructor (app, desktop) {
    this.win = null
    this.app = app
    this.desktop = desktop
    this.log = require('../../core-built/app.js').default.logger({
      component: 'GUI/' + this.windowOptions().title
    })

    let handlers = this.ipcEvents()
    Object.keys(handlers).forEach((name) => {
      if (!handlers[name]) {
        throw new Error('undefined handler for event ' + name)
      }
      ipcMain.on(name, handlers[name].bind(this))
    })
  }

  /* abtract */
  windowOptions () {
    throw new Error('extend WindowManager before using')
  }

  /* abtract */
  ipcEvents () {
    throw new Error('extend WindowManager before using')
  }

  makesAppVisible () {
    return true
  }

  show () {
    if (!this.win) return this.create()
    this.log.debug('show')
    this.win.show()
    return Promise.resolve(this.win)
  }

  hide () {
    if (this.win) {
      this.log.debug('hide')
      this.win.close()
    }
    this.win = null
  }

  shown () {
    return this.win != null
  }

  focus () {
    return this.win && this.win.focus()
  }

  reload () {
    if (this.win) {
      this.log.debug('reload')
      this.win.reload()
    }
  }

  send (...args) {
    this.win && this.win.webContents && this.win.webContents.send(...args)
  }

  hash () {
    return ''
  }

  create () {
    this.log.debug('create')
    const opts = this.windowOptions()
    opts.show = false
    this.win = new BrowserWindow(opts)

    // openExternalLinks
{'fraction_non_alphanumeric': 0.16282462795447913, 'fraction_numerical': 0.0026262036766851473, 'mean_word_length': 2.434869739478958, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4110494', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1110, 'n_words': 227}