<commit_before>// Copyright (c) 2013, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/**
 * Launch services.
 */
library spark.launch;

import 'dart:async';
import 'dart:html' as html;
import 'dart:typed_data' as typed_data;

import 'package:chrome/chrome_app.dart' as chrome;
import 'package:intl/intl.dart';
import 'package:logging/logging.dart';

import 'compiler.dart';
import 'server.dart';
import 'workspace.dart';

const int SERVER_PORT = 4040;

final Logger _logger = new Logger('spark.launch');

final NumberFormat _NF = new NumberFormat.decimalPattern();

/**
 * Manages all the launches and calls the appropriate delegate.
 */
class LaunchManager {

  List<LaunchDelegate> _delegates = [];

  /**
   * The last project that was launched
   */
  Project _currentProject;
  Project get currentProject => _currentProject;

  Workspace _workspace;
  Workspace get workspace => _workspace;

  LaunchManager(this._workspace) {
    _delegates.add(new DartWebAppLaunchDelegate(this));
    _delegates.add(new ChromeAppLaunchDelegate());
  }

  /**
   * Indicates whether a particular [Resource] can be run.
   */
  bool canRun(Resource resource) => _delegates.any((delegate) => delegate.canRun(resource));

  /**
   * Launches the given [Resouce].
   */
  void run(Resource resource) {
    _delegates.firstWhere((delegate) => delegate.canRun(resource)).run(resource);
  }

  void dispose() {
    _delegates.forEach((delegate) => delegate.dispose());
  }
}

/**
 * Provides convenience methods for launching. Clients can customize the launch
 * delegate.
 */
abstract class LaunchDelegate {
  /**
   * The delegate can launch the given resource
   */
  bool canRun(Resource resource);

  void run(Resource resource);

  void dispose();
}

/**
 * Launcher for running Dart web apps.
 */
class DartWebAppLaunchDelegate extends LaunchDelegate {

  PicoServer _server;
  LaunchManager _launchManager;
  Dart2JsServlet _dart2jsServlet;

  DartWebAppLaunchDelegate(this._launchManager) {
    _dart2jsServlet = new Dart2JsServlet(_launchManager);

    PicoServer.createServer(SERVER_PORT).then((server) {
      _server = server;
      _server.addServlet(new ProjectRedirectServlet(_launchManager));
      _server.addServlet(new StaticResourcesServlet());
      _server.addServlet(_dart2jsServlet);
      _server.addServlet(new WorkspaceServlet(_launchManager));
    });
  }

  // For now launching only web/index.html.
  bool canRun(Resource resource) {
    return resource.project != null && resource.project.getChildPath('web/index.html') is File;
  }

  void run(Resource resource) {
    _launchManager._currentProject = resource.project;
    // Use htm extension for launch page, otherwise polymer build tries to pick it up.
    chrome.app.window.create('launch_page.htm',
        new chrome.CreateWindowOptions(id: 'runWindow', width: 600, height: 800))
      .then((_) {},
          onError: (e) => _logger.log(Level.INFO, 'Error launching Dart web app', e));
  }

  void dispose() {<commit_msg>tweak launch window sizes<commit_after>// Copyright (c) 2013, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/**
 * Launch services.
 */
library spark.launch;

import 'dart:async';
import 'dart:html' as html;
import 'dart:typed_data' as typed_data;

import 'package:chrome/chrome_app.dart' as chrome;
import 'package:intl/intl.dart';
import 'package:logging/logging.dart';

import 'compiler.dart';
import 'server.dart';
import 'workspace.dart';

const int SERVER_PORT = 4040;

final Logger _logger = new Logger('spark.launch');

final NumberFormat _NF = new NumberFormat.decimalPattern();

/**
 * Manages all the launches and calls the appropriate delegate.
 */
class LaunchManager {

  List<LaunchDelegate> _delegates = [];

  /**
   * The last project that was launched
   */
  Project _currentProject;
  Project get currentProject => _currentProject;

  Workspace _workspace;
  Workspace get workspace => _workspace;

  LaunchManager(this._workspace) {
    _delegates.add(new DartWebAppLaunchDelegate(this));
    _delegates.add(new ChromeAppLaunchDelegate());
  }

  /**
   * Indicates whether a particular [Resource] can be run.
   */
  bool canRun(Resource resource) => _delegates.any((delegate) => delegate.canRun(resource));

  /**
   * Launches the given [Resouce].
   */
  void run(Resource resource) {
    _delegates.firstWhere((delegate) => delegate.canRun(resource)).run(resource);
  }

  void dispose() {
    _delegates.forEach((delegate) => delegate.dispose());
  }
}

/**
 * Provides convenience methods for launching. Clients can customize the launch
 * delegate.
 */
abstract class LaunchDelegate {
  /**
   * The delegate can launch the given resource
   */
  bool canRun(Resource resource);

  void run(Resource resource);

  void dispose();
}

/**
 * Launcher for running Dart web apps.
 */
class DartWebAppLaunchDelegate extends LaunchDelegate {

  PicoServer _server;
  LaunchManager _launchManager;
  Dart2JsServlet _dart2jsServlet;

  DartWebAppLaunchDelegate(this._launchManager) {
    _dart2jsServlet = new Dart2JsServlet(_launchManager);

    PicoServer.createServer(SERVER_PORT).then((server) {
      _server = server;
      _server.addServlet(new ProjectRedirectServlet(_launchManager));
      _server.addServlet(new StaticResourcesServlet());
      _server.addServlet(_dart2jsServlet);
      _server.addServlet(new WorkspaceServlet(_launchManager));
    });
  }

  // For now launching only web/index.html.
  bool canRun(Resource resource) {
    return resource.project != null && resource.project.getChildPath('web/index.html') is File;
  }

  void run(Resource resource) {
    _launchManager._currentProject = resource.project;
    // Use htm extension for launch page, otherwise polymer build tries to pick it up.
    var options = new chrome.CreateWindowOptions(
        id: 'runWindow',
        width: 800, height: 540,
        minWidth: 800, minHeight: 540);
    chrome.app.window.create('launch_page.htm', options).catchError((e) {
      _logger.log(Level.INFO, 'Error launching Dart web app', e);
    });
  }

  void dispose() {
{'fraction_non_alphanumeric': 0.11209486166007905, 'fraction_numerical': 0.006956521739130435, 'mean_word_length': 4.0126782884310614, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1037390', 'n_tokens_mistral': 1965, 'n_tokens_neox': 1844, 'n_words': 510}