UNPKG

nw-dev

Version:

A drop-in library for nw.js development

117 lines (112 loc) 3.46 kB
// Generated by CoffeeScript 1.10.0 (function() { var chokidar, err1, err2, error, error1, ignore, ignored, nwgui, nwwin, watcher, hasProp = {}.hasOwnProperty; window.CRASHED = false; if (typeof process !== "undefined" && process !== null) { nwgui = window.require("nw.gui"); nwwin = nwgui.Window.get(window); process.removeAllListeners("uncaughtException"); process.on("uncaughtException", function(e) { var ref; if (!window.CRASHED) { window.CRASHED = true; if (typeof console !== "undefined" && console !== null) { if (typeof console.warn === "function") { console.warn("CRASH"); } } nwwin.showDevTools(); } if (((ref = nwgui.App.manifest.window) != null ? ref.show : void 0) === false) { return nwwin.show(); } }); window.addEventListener("keydown", function(e) { var ref; switch ((ref = e.key) != null ? ref : e.keyIdentifier) { case "F12": return nwwin.showDevTools(); case "F5": return window.location.reload(); } }); ignored = [/node_modules|npm-debug\.log|\.git|\.hg|\.svn/]; ignore = document.currentScript.dataset.ignore; if (ignore) { ignored.push(ignore); } try { chokidar = window.require("nw-dev/node_modules/chokidar/"); } catch (error) { err1 = error; try { chokidar = window.require("chokidar"); } catch (error1) { err2 = error1; console.warn("Live reload disabled:", [err1.stack, err2.stack]); } } if (chokidar) { watcher = chokidar.watch(".", { ignored: ignored }); watcher.on("change", function(path) { var fs, height, k, newwin, newwin_options, pkg, ref, ref1, ref2, v, width, x, y; watcher.close(); ref = global.require.cache; for (k in ref) { if (!hasProp.call(ref, k)) continue; delete global.require.cache[k]; } nwwin.removeAllListeners(); nwwin.closeDevTools(); if (path === "package.json") { fs = require("fs"); pkg = JSON.parse(fs.readFileSync("package.json", "utf8")); Object.defineProperty(nwgui.App, "manifest", { value: pkg, configurable: true }); x = nwwin.x, y = nwwin.y; width = window.innerWidth; height = window.innerHeight; window.close(); newwin_options = {}; ref1 = pkg.window; for (k in ref1) { v = ref1[k]; newwin_options[k] = v; } ref2 = { x: x, y: y, width: width, height: height }; for (k in ref2) { v = ref2[k]; newwin_options[k] = v; } return newwin = nwgui.Window.open(window.location.href, newwin_options); } else { return typeof location !== "undefined" && location !== null ? location.reload() : void 0; } }); } } window.onerror = function(e) { if (!window.CRASHED) { window.CRASHED = true; if (typeof console !== "undefined" && console !== null) { if (typeof console.warn === "function") { console.warn("CRASH"); } } if (nwwin != null) { nwwin.showDevTools(); } } return false; }; }).call(this);