<commit_before>import { app, BrowserWindow, ipcMain, screen } from 'electron';
import loadDevtool from 'electron-load-devtool';
import path from 'path';
import url from 'url';

let window: Electron.BrowserWindow | null = null;
let subWindow: Electron.BrowserWindow | null = null;
let ignoreMouseEvents = false;

function createWindow(): void {
  window = new BrowserWindow({
    width: 600,
    height: 600,
  });

  window.loadURL(url.format({
    pathname: path.join(__dirname, '..', 'renderer', 'pages', 'index.html'),
    protocol: 'file:',
    slashes: true,
  }));

  window.on('closed', () => {
    window = null;

    if (subWindow !== null) {
      subWindow.close();
    }
  });
}

app.on('ready', () => {
  createWindow();

  if (process.env.NODE_ENV === 'development') {
    loadDevtool(loadDevtool['REACT_DEVELOPER_TOOLS']);
    loadDevtool(loadDevtool['REDUX_DEVTOOLS']);
    window!.webContents.openDevTools();
  }
});

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  if (window === null) {
    createWindow();
  }
});

ipcMain.on('open-subwindow-request', (e) => {
  if (subWindow !== null) {
    console.log('received open-subwindow-request but subwindow is already open');
    return;
  }
  subWindow = new BrowserWindow({
    x: 1620,
    y: 80,
    width: 800,
    height: 400,
    transparent: true,
    frame: false,
    resizable: false, // TODO: should be false because break transparency on some platforms
    alwaysOnTop: true,
  });

  subWindow.setIgnoreMouseEvents(ignoreMouseEvents = true);

  subWindow.loadURL(url.format({
    pathname: path.join(__dirname, '..', 'renderer', 'pages', 'sub.html'),
    protocol: 'file:',
    slashes: true,
  }));

  subWindow.on('closed', () => {
    subWindow = null;
  });

  if (process.env.NODE_ENV === 'development') {
    subWindow.webContents.openDevTools();
  }
});

ipcMain.on('new-posts', (e, newPosts) => {
  if (subWindow) {
    subWindow.webContents.send('new-posts', newPosts);<commit_msg>fix: リンクをクリックしたときにウィンドウが開かれないようにする<commit_after>import { app, BrowserWindow, ipcMain, screen } from 'electron';
import loadDevtool from 'electron-load-devtool';
import path from 'path';
import url from 'url';

let window: Electron.BrowserWindow | null = null;
let subWindow: Electron.BrowserWindow | null = null;
let ignoreMouseEvents = false;

function createWindow(): void {
  window = new BrowserWindow({
    width: 600,
    height: 600,
  });

  window.webContents.on('new-window', handleNewWindow);

  window.loadURL(url.format({
    pathname: path.join(__dirname, '..', 'renderer', 'pages', 'index.html'),
    protocol: 'file:',
    slashes: true,
  }));

  window.on('closed', () => {
    window = null;

    if (subWindow !== null) {
      subWindow.close();
    }
  });
}

const handleNewWindow = (e: any, url: string) => {
  e.preventDefault();
  // TODO: process url
};

app.on('ready', () => {
  createWindow();

  if (process.env.NODE_ENV === 'development') {
    loadDevtool(loadDevtool['REACT_DEVELOPER_TOOLS']);
    loadDevtool(loadDevtool['REDUX_DEVTOOLS']);
    window!.webContents.openDevTools();
  }
});

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  if (window === null) {
    createWindow();
  }
});

ipcMain.on('open-subwindow-request', (e) => {
  if (subWindow !== null) {
    console.log('received open-subwindow-request but subwindow is already open');
    return;
  }
  subWindow = new BrowserWindow({
    x: 1620,
    y: 80,
    width: 800,
    height: 400,
    transparent: true,
    frame: false,
    resizable: false, // TODO: should be false because break transparency on some platforms
    alwaysOnTop: true,
  });

  subWindow.on('new-window', handleNewWindow);

  subWindow.setIgnoreMouseEvents(ignoreMouseEvents = true);

  subWindow.loadURL(url.format({
    pathname: path.join(__dirname, '..', 'renderer', 'pages', 'sub.html'),
    protocol: 'file:',
    slashes: true,
  }));

  subWindow.on('closed', () => {
    subWindow = null;
  });

  if (process.env.NODE_ENV === 'development') {
    subWindow.webContents.openDevTools();
  }
});

ipcMain.on('new-posts', (e, newPosts) => {
  if (subWindow) {
    subWindow.webContents.send('new-posts', newPosts);
{'fraction_non_alphanumeric': 0.17568192325473878, 'fraction_numerical': 0.008321775312066574, 'mean_word_length': 3.6627155172413794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '870907', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1450, 'n_words': 304}