Skip to content

Commit

Permalink
(Probably) fix multiple issues with windows
Browse files Browse the repository at this point in the history
...by using latest nightly build of nw.js.
At least on Linux there is no more process "exit" event on child window
close.
  • Loading branch information
Kagami committed Jan 10, 2016
1 parent b5a2f7b commit df16ab8
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 74 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
NAME = wybm
VERSION := $(shell npm -j version | awk -F '"' '/"wybm"/{print $$4}')
DIST_DIR = dist
LIN64_NW_DIR = bin/nwjs-v0.13.0-beta2-linux-x64
LIN64_NW_DIR = bin/nwjs-v0.13.0-beta3-linux-x64
LIN64_APP = app-v$(VERSION)-linux-x64.nw
LIN64_RELEASE = $(NAME)-v$(VERSION)-linux-x64
LIN64_RELEASE_DIR = $(DIST_DIR)/$(LIN64_RELEASE)
LIN64_ZIP = $(LIN64_RELEASE).7z
WIN32_NW_DIR = bin/nwjs-v0.13.0-beta2-win-ia32
WIN32_NW_DIR = bin/nwjs-v0.13.0-beta3-win-ia32
WIN32_APP = app-v$(VERSION)-win-x86.nw
WIN32_RELEASE = $(NAME)-v$(VERSION)-win-x86
WIN32_RELEASE_DIR = $(DIST_DIR)/$(WIN32_RELEASE)
Expand Down
23 changes: 9 additions & 14 deletions src/dialog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@ export function alert(opts) {
let wybm = win.wybm = new EventEmitter();
wybm.opts = opts;
wybm.on("ok", () => {
win.close(true);
win.close();
resolve();
});
// NOTE(Kagami): We have to setup close event on child windows if
// "close" handler on parent window was defined. Otherwise child
// won't close.
win.on("close", () => {
win.close(true);
win.on("closed", () => {
resolve();
});
});
Expand All @@ -63,15 +59,15 @@ export function confirm(opts) {
let wybm = win.wybm = new EventEmitter();
wybm.opts = opts;
wybm.on("ok", () => {
win.close(true);
win.close();
resolve();
});
wybm.on("cancel", () => {
win.close(true);
win.close();
reject(new Error("Cancel"));
});
win.on("close", () => {
win.close(true);
win.on("closed", () => {
// Will fire even after ok&resolve but won't harm.
reject(new Error("Cancel"));
});
});
Expand All @@ -91,15 +87,14 @@ export function prompt(opts) {
let wybm = win.wybm = new EventEmitter();
wybm.opts = opts;
wybm.on("ok", value => {
win.close(true);
win.close();
resolve(value);
});
wybm.on("cancel", () => {
win.close(true);
win.close();
reject(new Error("Cancel"));
});
win.on("close", () => {
win.close(true);
win.on("closed", () => {
reject(new Error("Cancel"));
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/ffmpeg/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import {spawn} from "child_process";
import {tmp} from "../util";
import tmp from "tmp";
if (WIN_BUILD) {
// TODO(Kagami): Allow to use system ffmpeg.
require("file?name=[name].[ext]!../../bin/ffmpeg.exe");
Expand Down
2 changes: 2 additions & 0 deletions src/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @module wybm/index
*/

import tmp from "tmp";
import React from "react";
import ReactDOM from "react-dom";
import Source from "../source";
Expand Down Expand Up @@ -43,4 +44,5 @@ const Index = React.createClass({
},
});

tmp.setGracefulCleanup();
ReactDOM.render(<Index/>, document.getElementById("wybm-index"));
3 changes: 2 additions & 1 deletion src/source/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

import fs from "fs";
import path from "path";
import tmp from "tmp";
import request from "request";
import React from "react";
import FFmpeg from "../ffmpeg";
import {ShowHide, showSize, showErr, tmp} from "../util";
import {ShowHide, showSize, showErr} from "../util";

export default React.createClass({
getInitialState() {
Expand Down
6 changes: 2 additions & 4 deletions src/source/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import assert from "assert";
import React from "react";
import {showSize, toCapitalCase} from "../util";
import * as dialog from "../dialog";

export default React.createClass({
componentDidMount() {
Expand Down Expand Up @@ -120,9 +121,6 @@ export default React.createClass({
audio: audio ? Object.assign({}, audio) : null,
});
},
handleCancelClick() {
this.props.onCancel();
},
render() {
return (
<div>
Expand Down Expand Up @@ -158,7 +156,7 @@ export default React.createClass({
value="Cancel"
type="button"
style={this.styles.bigButton}
onClick={this.handleCancelClick}
onClick={this.props.onCancel}
/>
</div>
);
Expand Down
51 changes: 0 additions & 51 deletions src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import assert from "assert";
import _tmp from "tmp";

export {default as ShowHide} from "./show-hide";

Expand Down Expand Up @@ -84,53 +83,3 @@ export function popkeys(obj, keys) {
keys.forEach(key => delete copy[key]);
return copy;
}

// XXX(Kagami): We got process "exit" event on child window close so
// "tmp" library cleanup will delete all current temporary files which
// is unacceptable. So we need to wrap tmp calls and clean everything on
// main window close by ourself. Defining "close" event also affects
// child windows (see dialog module).
// This way we should actually always remove all temp objects though,
// even on Ctrl+C (see <https://github.com/raszi/node-tmp/issues/18>).
export const tmp = (function() {
let removes = [];
function cleanup() {
while (removes.length) {
try {
removes.shift()();
} catch(e) {
/* skip */
}
}
}

let win = window.nw.Window.get();
win.on("close", function() {
win.hide();
cleanup();
win.close(true);
});

// TODO(Kagami): This won't work on Windows (see
// <https://stackoverflow.com/q/10021373>).
process.on("SIGINT", function() {
cleanup();
});

// Tiny subset of API which we actually use but fully compatible with
// tmp module.
return {
fileSync(opts) {
opts = Object.assign({}, opts, {keep: true});
const tmpObj = _tmp.fileSync(opts);
removes.push(tmpObj.removeCallback);
return tmpObj;
},
dirSync(opts) {
opts = Object.assign({}, opts, {keep: true});
const tmpObj = _tmp.dirSync(opts);
removes.push(tmpObj.removeCallback);
return tmpObj;
},
};
})();
3 changes: 2 additions & 1 deletion src/view/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
*/

import fs from "fs";
import tmp from "tmp";
import React from "react";
import FFmpeg from "../ffmpeg";
import {Center, Header, Text, Br, BigButton} from "../theme";
import {ShowHide, showErr, showSize, tmp} from "../util";
import {ShowHide, showErr, showSize} from "../util";

export default React.createClass({
getInitialState() {
Expand Down

0 comments on commit df16ab8

Please sign in to comment.