Skip to content

Commit 002d55f

Browse files
Merge pull request #791 from iNavFlight/dzikuvx-fix-chrome-app
Fix app not starting in chrome
2 parents 1633ea9 + 4a0bf7b commit 002d55f

File tree

3 files changed

+1544
-1372
lines changed

3 files changed

+1544
-1372
lines changed

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ sources.js = [
6161
'./js/libraries/d3.min.js',
6262
'./js/libraries/jquery.nouislider.all.min.js',
6363
'./node_modules/three/three.min.js',
64-
'./node_modules/nw-dialog/index.js',
64+
'./js/libraries/nw-dialog.js',
6565
'./js/libraries/bundle_xml2js.js',
6666
'./js/libraries/Projector.js',
6767
'./js/libraries/CanvasRenderer.js',

js/libraries/nw-dialog.js

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
'use strict';
2+
3+
var nwdialog = {
4+
5+
_context: (typeof global === 'undefined' || typeof global.DOMDocument === 'undefined') ? document : global.DOMDocument,
6+
7+
setContext: function(context) {
8+
this._context = context;
9+
},
10+
11+
openFileDialog: function(filter, multiple, workdir, callback) {
12+
13+
var fn = callback;
14+
var node = this._context.createElement('input');
15+
node.type = 'file';
16+
node.id = 'open-file-dialog';
17+
node.style = 'display: none';
18+
19+
if (typeof filter === 'function') {
20+
fn = filter;
21+
} else if (typeof filter === 'string') {
22+
node.setAttribute('accept', filter);
23+
} else if (typeof filter === 'boolean' && filter === true) {
24+
node.setAttribute('multiple', '');
25+
} else if (this.isArray(filter)) {
26+
node.setAttribute('accept', filter.join(','));
27+
}
28+
29+
if (typeof multiple === 'function') {
30+
fn = multiple;
31+
} else if (typeof multiple === 'string') {
32+
node.setAttribute('nwworkingdir', multiple);
33+
} else if (typeof multiple === 'boolean' && multiple === true) {
34+
node.setAttribute('multiple', '');
35+
}
36+
37+
if (typeof workdir === 'function') {
38+
fn = workdir;
39+
} else if (typeof workdir === 'string') {
40+
node.setAttribute('nwworkingdir', workdir);
41+
}
42+
43+
this._context.body.appendChild(node);
44+
node.addEventListener('change', function(e) {
45+
fn(node.value);
46+
node.remove();
47+
});
48+
node.click();
49+
50+
},
51+
52+
saveFileDialog: function(name, accept, directory, callback) {
53+
54+
var fn = callback;
55+
var node = this._context.createElement('input');
56+
node.type = 'file';
57+
node.id = 'save-file-dialog';
58+
node.style = 'display: none';
59+
node.setAttribute('nwsaveas', '');
60+
61+
if (typeof name === 'function') {
62+
fn = name;
63+
} else if (typeof name === 'string') {
64+
node.setAttribute('nwsaveas', name);
65+
}
66+
67+
if (typeof accept === 'function') {
68+
fn = accept;
69+
} else if (typeof accept === 'string') {
70+
node.setAttribute('accept', accept);
71+
} else if (this.isArray(accept)) {
72+
node.setAttribute('accept', accept.join(','));
73+
}
74+
75+
if (typeof directory === 'function') {
76+
fn = directory;
77+
} else if (typeof directory === 'string') {
78+
node.setAttribute('nwworkingdir', directory);
79+
}
80+
81+
this._context.body.appendChild(node);
82+
node.addEventListener('change', function() {
83+
fn(node.value);
84+
node.remove();
85+
});
86+
node.click();
87+
88+
},
89+
90+
folderBrowserDialog: function(workdir, callback) {
91+
var fn = callback;
92+
var node = this._context.createElement('input');
93+
node.type = 'file';
94+
node.id = 'folder-browser-dialog';
95+
node.style = 'display: none';
96+
node.nwdirectory= true;
97+
98+
if (typeof workdir === 'function') {
99+
fn = workdir
100+
} else if (typeof workdir === 'string') {
101+
node.setAttribute('nwworkingdir', workdir);
102+
}
103+
104+
this._context.body.appendChild(node);
105+
node.addEventListener('change', function() {
106+
fn(node.value);
107+
node.remove();
108+
});
109+
node.click();
110+
},
111+
112+
isArray: function(value) {
113+
return Object.prototype.toString.call(value) === '[object Array]';
114+
}
115+
116+
}
117+
118+
if (typeof nw !== 'undefined') {
119+
if (typeof exports == 'undefined') {
120+
nw.Dialog = nwdialog;
121+
window.dialog = nwdialog;
122+
} else {
123+
module.exports = nwdialog;
124+
}
125+
}

0 commit comments

Comments
 (0)