Example #1
0
import * as path from 'path';
import * as appConfig from './app-config';

let window:any;

var createWindow = () => {
    window = new Electron.BrowserWindow({
        width: 1400,
        height: 800,
        title: 'Hello World'
    });
    window.loadURL(`file://${path.join(appConfig.APP_TEMPLATE_PATH, '/index.html')}`);
    // window.webContents.openDevTools();
    window.on('closed', () => {
        window = null;
    });
};

Electron.app.on('ready', createWindow);

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

Electron.app.on('activate', () => {
    if (window == null) {
        createWindow();
    }
});
Example #2
0
app.once('window-all-closed', () => app.quit());
Example #3
0
	constructor() {
		this._appRoot = path.dirname(URI.parse(require.toUrl('')).fsPath);
		this._currentWorkingDirectory = process.env['VSCODE_CWD'] || process.cwd();
		this._appHome = app.getPath('userData');
		this._appSettingsHome = path.join(this._appHome, 'User');
		this._appSettingsPath = path.join(this._appSettingsHome, 'settings.json');
		this._appKeybindingsPath = path.join(this._appSettingsHome, 'keybindings.json');

		// Remove the Electron executable
		let [, ...args] = process.argv;

		// If dev, remove the first non-option argument: it's the app location
		if (!this.isBuilt) {
			const index = arrays.firstIndex(args, a => !/^-/.test(a));

			if (index > -1) {
				args.splice(index, 1);
			}
		}

		// Finally, prepend any extra arguments from the 'argv' file
		if (fs.existsSync(path.join(this._appRoot, 'argv'))) {
			const extraargs: string[] = JSON.parse(fs.readFileSync(path.join(this._appRoot, 'argv'), 'utf8'));
			args = [...extraargs, ...args];
		}

		const argv = parseArgs(args);

		const debugBrkExtensionHostPort = getNumericValue(argv.debugBrkPluginHost, 5870);
		const debugExtensionHostPort = getNumericValue(argv.debugPluginHost, 5870, this.isBuilt ? void 0 : 5870);
		const pathArguments = parsePathArguments(this._currentWorkingDirectory, argv._, argv.goto);
		const timestamp = parseInt(argv.timestamp);
		const debugBrkFileWatcherPort = getNumericValue(argv.debugBrkFileWatcherPort, void 0);

		this._cliArgs = Object.freeze({
			pathArguments: pathArguments,
			programStart: types.isNumber(timestamp) ? timestamp : 0,
			enablePerformance: argv.performance,
			verboseLogging: argv.verbose,
			debugExtensionHostPort: debugBrkExtensionHostPort || debugExtensionHostPort,
			debugBrkExtensionHost: !!debugBrkExtensionHostPort,
			logExtensionHostCommunication: argv.logExtensionHostCommunication,
			debugBrkFileWatcherPort: debugBrkFileWatcherPort,
			openNewWindow: argv['new-window'],
			openInSameWindow: argv['reuse-window'],
			gotoLineMode: argv.goto,
			diffMode: argv.diff && pathArguments.length === 2,
			extensionsHomePath: normalizePath(argv.extensionHomePath),
			extensionDevelopmentPath: normalizePath(argv.extensionDevelopmentPath),
			extensionTestsPath: normalizePath(argv.extensionTestsPath),
			disableExtensions: argv['disable-extensions'],
			locale: argv.locale,
			waitForWindowClose: argv.wait
		});

		this._isTestingFromCli = this.cliArgs.extensionTestsPath && !this.cliArgs.debugBrkExtensionHost;
		this._userHome = path.join(os.homedir(), product.dataFolderName);
		this._userExtensionsHome = this.cliArgs.extensionsHomePath || path.join(this._userHome, 'extensions');
		this._mainIPCHandle = this.getMainIPCHandle();
		this._sharedIPCHandle = this.getSharedIPCHandle();
	}
Example #4
0
    protocol,
    Tray,
    clipboard,
    crashReporter,
    nativeImage,
    screen,
    shell
} from 'electron'

// crashReporter.start(null)

var mainWindow: Electron.BrowserWindow = null;

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

app.on('ready', () => {
    mainWindow = new BrowserWindow({
        width: 800,
        height: 600
    })
    mainWindow.loadURL('file://' + __dirname + '/../../index.html')

    mainWindow.on('closed', () => {
        mainWindow = null
    })
})
Example #5
0
 .subscribe(() => {
     if (process.platform !== `darwin`) {
         app.quit();
     }
 });
Example #6
0
import { app, dialog, BrowserWindow, shell, ipcMain } from 'electron'
import * as path from 'path'

let mainWindow: BrowserWindow | null = null

// Quit when all windows are closed.
app.on('window-all-closed', () => {
  app.quit()
})

function decorateURL (url: string) {
  // safely add `?utm_source=default_app
  const parsedUrl = new URL(url)
  parsedUrl.searchParams.append('utm_source', 'default_app')
  return parsedUrl.toString()
}

// Find the shortest path to the electron binary
const absoluteElectronPath = process.execPath
const relativeElectronPath = path.relative(process.cwd(), absoluteElectronPath)
const electronPath = absoluteElectronPath.length < relativeElectronPath.length
  ? absoluteElectronPath
  : relativeElectronPath

const indexPath = path.resolve(app.getAppPath(), 'index.html')

function isTrustedSender (webContents: Electron.WebContents) {
  if (webContents !== (mainWindow && mainWindow.webContents)) {
    return false
  }
Example #7
0
import "source-map-support/register";
import * as util from "util";
import { app, BrowserWindow, ipcMain } from "electron";

let windows: GitHubElectron.BrowserWindow[] = [];

let openWindow = (uri: string, options: GitHubElectron.BrowserWindowOptions) => {
    let window = new BrowserWindow(options);
    windows.push(window);
    window.loadURL("file://" + __dirname + uri);
    window.on("closed", () => windows.splice(windows.indexOf(window)));
};

app.on("window-all-closed", () => {
    // FIXME: quit on close should be a setting
    // if (process.platform != "darwin") {
    app.quit();
    // }
});

app.on("ready", () => {
    ipcMain.on("console-log", (event, msg, ...args) => {
        if (typeof msg !== "string") {
            msg = util.inspect(msg);
        }
        console.log("[Browser] " + msg, ...args);
    });
    ipcMain.on("console-error", (event, msg, ...args) => {
        if (typeof msg !== "string") {
            msg = util.inspect(msg);
        }
        console.error("[Browser ERROR] " + msg, ...args);
Example #8
0
 index => {
   if (index === 0) {
     app.quit();
   }
 }
Example #9
0
const electronReady$ = new Observable(observer => {
  app.on("ready", (event: Event) => observer.next(event));
});
Example #10
0
const windowAllClosed = new Observable(observer => {
  app.on("window-all-closed", (event: Event) => observer.next(event));
});
Example #11
0
 return () => app.removeListener(eventName, handler);
Example #12
0
ipc.on("open-notebook", (_event: any, filename: string) => {
  launch(resolve(filename));
});

ipc.on("reload", (event: Event) => {
  event.sender.reload();
  event.returnValue = null;
});

ipc.on("show-message-box", (event: Event, arg: any) => {
  const response = dialog.showMessageBox(arg);
  event.sender.send("show-message-box-response", response);
});

app.on("ready", initAutoUpdater);

const electronReady$ = new Observable(observer => {
  app.on("ready", (event: Event) => observer.next(event));
});
const windowReady$ = fromEvent(ipc, "react-ready");

const fullAppReady$ = zip(electronReady$, prepareEnv).pipe(first());

const jupyterConfigDir = join(app.getPath("home"), ".jupyter");
const nteractConfigFilename = join(jupyterConfigDir, "nteract.json");

const prepJupyterObservable = prepareEnv.pipe(
  mergeMap(() =>
    // Create all the directories we need in parallel
    forkJoin(
Example #13
0
import urls from "common/constants/urls";
import env from "common/env";
import { I18nKeys, I18nResources, Store } from "common/types";
import { getLocalePath, getLocalesConfigPath } from "common/util/resources";
import { Watcher } from "common/util/watcher";
import { app } from "electron";
import { mainLogger } from "main/logger";
import { join } from "path";
import { request } from "main/net/request";
import { exists, readFile, writeFile } from "main/os/ifs";

const upgradesEnabled =
  (env.production && !env.integrationTests) ||
  process.env.DID_I_STUTTER === "1";

const remoteDir = join(app.getPath("userData"), "locales");
const localesConfigPath = getLocalesConfigPath();

const logger = mainLogger.child(__filename);

function canonicalFileName(lang: string): string {
  return getLocalePath(`${lang}.json`);
}

function remoteFileName(lang: string): string {
  return join(remoteDir, `${lang}.json`);
}

async function doDownloadLocale(
  lang: string,
  resources: I18nResources,
Example #14
0
Electron.app.on('window-all-closed', () => {
    if (process.platform !== 'drawin') {
        Electron.app.quit();
    }
});
Example #15
0
import {app, Menu, ipcMain} from 'electron'
import windowManager from './windowManager'
import menu from './menu'

ipcMain.on('create patternManager', function (event, arg) {
  windowManager.create('patternManager', arg)
})

ipcMain.on('dispatch', function (event, action, arg) {
  windowManager.dispatch(action, arg)
})

// Quit when all windows are closed.
app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})

app.on('activate', function (e, hasVisibleWindows) {
  if (!hasVisibleWindows) {
    windowManager.create()
  }
})

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function () {
  Menu.setApplicationMenu(menu)
  windowManager.create()
})
        win.on('closed', () => {
            win = null

            app.quit()
        })
Example #17
0
app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') {
    app.quit()
  }
})
 constructor() {
     app.on('before-quit', this.beforeQuit)
     app.on('ready', this.ready)
 }
Example #19
0
app.on('window-all-closed', () => {
  app.quit()
})
 private onWindowAllClosed(): void {
     if (process.platform !== 'darwin') {
         app.quit();
     }
 }
Example #21
0
app.on("window-all-closed", () => {
    // FIXME: quit on close should be a setting
    // if (process.platform != "darwin") {
    app.quit();
    // }
});
 constructor () {
     app.on('ready', this.onReady.bind(this));
     app.on('window-all-closed', this.onWindowAllClosed.bind(this));
     app.on('activate', this.onWindowActive.bind(this));
 }
Example #23
0
app.on('window-all-closed', () => {
    if (process.platform != 'darwin') {
        app.quit()
    }
})
Example #24
0
 click: () => {
   app.quit();
 }
Example #25
0
import {app, BrowserWindow, shell, nativeImage} from 'electron';
import {sync as mkdirpSync} from 'mkdirp';
import setMenu from './menu';
import BrowserConfig from './browser-config';

if (process.argv.indexOf('--help') !== -1) {
    console.log(`OVERVIEW: NyaoVim; Web-enhanced Extensible Neovim Frontend

USAGE: nyaovim [options] [neovim args...]

OPTIONS:
  --no-detach : Don't detach the editor process
  --help      : Show this help
  --version   : Show versions of NyaoVim, Electron, Chrome, Node.js, and V8
`);
    app.quit();
}

if (process.argv.indexOf('--version') !== -1) {
    const vs: {[n: string]: string} = process.versions as any;
    const versions = ['electron', 'chrome', 'node', 'v8'].map((n: string) => `  ${n} : ${vs[n]}`).join('\n');
    console.log(`${app.getName()} version ${app.getVersion()}
${versions}
`);
    app.quit();
}

process.on('unhandledRejection', (reason: string, p: Promise<any>) => {
    console.error('Fatal: Unhandled rejection at: Promise', p, 'Reason:', reason);
});
/// <reference path="electron-window-state.d.ts" />

import {app, BrowserWindow} from 'electron';
import windowStateKeeper = require('electron-window-state');

let win: Electron.BrowserWindow = null;

app.on('ready', function () {
  const mainWindowState = windowStateKeeper({
    defaultWidth: 1000,
    defaultHeight: 800
  });

  win = new BrowserWindow({
    'x': mainWindowState.x,
    'y': mainWindowState.y,
    'width': mainWindowState.width,
    'height': mainWindowState.height,
  });

  mainWindowState.manage(win);
});

const s2 = windowStateKeeper({
  defaultWidth: 1000,
  defaultHeight: 800,
  file: __dirname + '/foo.json',
  path: __dirname,
  maximize: true,
  fullScreen: false,
});
Example #27
0
import * as _ from "lodash";
import * as fs from "fs-extra";
import * as os from "os";
import * as path from "path";
import * as utils from "./utils";
import { app } from "electron";
const log = utils.getLogger("shell-config");

const CONFIG_PATH = path.resolve(utils.convertWindowsPathToUnixPath(app.getPath("userData")), "shell-config.json");
let config: {};

if (!process.env.TMPDIR && !process.env.TMP && !process.env.TEMP) {
    process.env.TMPDIR = process.env.TMP = process.env.TEMP = os.tmpdir();
}

function readDefaultConfig() {
    config = fs.readJsonSync(path.resolve(__dirname, "default-shell-config.json"));
}

function writeDefaultConfig() {
    readDefaultConfig();
    fs.ensureDirSync(path.dirname(CONFIG_PATH));
    fs.writeJsonSync(CONFIG_PATH, config);
}

try {
    config = fs.readJsonSync(CONFIG_PATH);
} catch (err) {
    if (err.code === "ENOENT") {
        writeDefaultConfig();
    } else if (err.name === "SyntaxError") {
    mainWindow.loadFile('dist.electron/index.html');
  }

  // Emitted when the window is closed.
  mainWindow.on('closed', () => {
    // Dereference the window object, usually you would store window
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;
  });
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);

// Quit when all windows are closed.
app.on('window-all-closed', () => {
  // On OS X it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
   app.quit();
  }
});

app.on('activate', () => {
  // On OS X it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (mainWindow === null) {
   createWindow();
Example #29
0
File: main.ts Project: itchio/itch
 app.on("will-finish-launching", () => {
   app.setAppUserModelId(appUserModelId);
 });
Example #30
0
import * as path from "path";
import Electron from "electron";
import * as fs from "fs";
import { Validator, Schema } from "jsonschema";

const validator = new Validator();
const folder = Electron.app.getPath("userData");

function load(file: string, schema: any) {
  if (!fs.existsSync(file)) {
    return undefined;
  }
  try {
    const data = fs.readFileSync(file, "utf8");
    const obj = JSON.parse(data);
    const result = validator.validate(obj, schema);
    if (result.errors.length === 0) {
      return obj;
    } else {
      console.error(`invalid JSON data found in ${name}`, result.errors);
      return undefined;
    }
  } catch (e) {
    console.error(`failed to load JSON data from ${name}`, e);
    return undefined;
  }
}

function replaceObjectContent(dest: any, src: any) {
  Object.getOwnPropertyNames(dest).forEach(name => {
    delete dest[name];