Skip to content

Commit aec20ff

Browse files
committed
Implement #124 - Add sdk-build support
Support added for SDK builds by adding a checkbox in Download Settings. This setting will download the SDK build if NW.js version is greater than or equal to 0.13.0.
1 parent 3556a45 commit aec20ff

File tree

4 files changed

+55
-35
lines changed

4 files changed

+55
-35
lines changed

command_line.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def get_file_information_from_url(self):
164164
self.extract_class = TarFile.open
165165
self.extract_args = ('r:gz',)
166166

167-
def save_file_path(self, version, location=None):
167+
def save_file_path(self, version, location=None, sdk_build=False):
168168
if location:
169169
self.save_path = location
170170
else:
@@ -185,6 +185,9 @@ def save_file_path(self, version, location=None):
185185
if minor >= 12 or major > 0:
186186
path = path.replace('node-webkit', 'nwjs')
187187

188+
if sdk_build:
189+
path = utils.replace_right(path, 'nwjs', 'nwjs-sdk', 1)
190+
188191
return path
189192

190193
return ''
@@ -193,11 +196,11 @@ def set_extra_attributes_from_keyword_args(self, **kwargs):
193196
for undefined_key, undefined_value in kwargs.items():
194197
setattr(self, undefined_key, undefined_value)
195198

196-
def extract(self, ex_path, version):
199+
def extract(self, ex_path, version, sdk_build=False):
197200
if os.path.exists(ex_path):
198201
utils.rmtree(ex_path, ignore_errors=True)
199202

200-
path = self.save_file_path(version)
203+
path = self.save_file_path(version, sdk_build=sdk_build)
201204

202205
file = self.extract_class(path,
203206
*self.extract_args)
@@ -400,11 +403,17 @@ def download_file_with_error_handling(self):
400403
path = setting.url.format(version, version)
401404
versions = re.findall('(\d+)\.(\d+)\.(\d+)', version)[0]
402405

406+
sdk_build_setting = self.get_setting('sdk_build')
407+
sdk_build = sdk_build_setting.value
408+
403409
minor = int(versions[1])
404410
major = int(versions[0])
405411
if minor >= 12 or major > 0:
406412
path = path.replace('node-webkit', 'nwjs')
407413

414+
if minor >= 13 and sdk_build:
415+
path = utils.replace_right(path, 'nwjs', 'nwjs-sdk', 1)
416+
408417
try:
409418
return self.download_file(setting.url.format(version, version),
410419
setting)
@@ -576,15 +585,18 @@ def extract_files(self):
576585
self.extract_error = None
577586
location = self.get_setting('download_dir').value
578587

588+
sdk_build_setting = self.get_setting('sdk_build')
589+
sdk_build = sdk_build_setting.value
579590
version = self.selected_version()
580591

581592
for setting_name, setting in self.settings['export_settings'].items():
582593
save_file_path = setting.save_file_path(version,
583-
location)
594+
location,
595+
sdk_build)
584596
try:
585597
if setting.value:
586598
extract_path = get_data_path('files/'+setting.name)
587-
setting.extract(extract_path, version)
599+
setting.extract(extract_path, version, sdk_build)
588600

589601
self.progress_text += '.'
590602

@@ -1202,14 +1214,20 @@ def download_file(self, path, setting):
12021214

12031215
location = self.get_setting('download_dir').value
12041216

1217+
sdk_build_setting = self.get_setting('sdk_build')
1218+
sdk_build = sdk_build_setting.value
1219+
12051220
versions = self.get_version_tuple()
12061221
major, minor, _ = versions
12071222

12081223
if minor >= 12 or major > 0:
12091224
path = path.replace('node-webkit', 'nwjs')
12101225

1226+
if minor >= 13 and sdk_build:
1227+
path = utils.replace_right(path, 'nwjs', 'nwjs-sdk', 1)
1228+
12111229
url = path
1212-
file_name = setting.save_file_path(self.selected_version(), location)
1230+
file_name = setting.save_file_path(self.selected_version(), location, sdk_build)
12131231
tmp_file = list(os.path.split(file_name))
12141232
tmp_file[-1] = '.tmp.' + tmp_file[-1]
12151233
tmp_file = os.sep.join(tmp_file)

files/settings.cfg

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ linux_64_dir_prefix = 'node-webkit-v{}-linux-x64'
5050
display_name='Single Instance'
5151
default_value=True
5252
type='check'
53-
description='Restrict the app to run with only a single instance allowed at a time.'
53+
description='Restrict the app to run with only a single instance\nallowed at a time. Deprecated in NW.js >= 0.13.0'
5454
[[[user-agent]]]
5555
display_name='User Agent'
5656
default_value=''
@@ -60,39 +60,39 @@ linux_64_dir_prefix = 'node-webkit-v{}-linux-x64'
6060
display_name='Node Remote'
6161
default_value=''
6262
type='string'
63-
description='Enable calling node in remote pages. See the node-webkit manifest format for more info.'
63+
description='Enable calling node in remote pages. See the node-webkit\nmanifest format for more info.'
6464
[[[chromium-args]]]
6565
display_name='Chromium Args'
6666
default_value=''
6767
type='string'
68-
description='Specify chromium command line arguments. Example value: "--disable-accelerated-video --force-cpu-draw"'
68+
description='Specify chromium command line arguments.\nExample value: "--disable-accelerated-video --force-cpu-draw"'
6969
[[[js-flags]]]
7070
display_name='JS Flags'
7171
default_value=''
7272
type='string'
73-
description='Specify flags passed to the js engine. Example value: "--harmony_proxies --harmony_collecions"'
73+
description='Specify flags passed to the js engine.\nExample value: "--harmony_proxies --harmony_collecions"'
7474
[[[inject-js-start]]]
7575
display_name='Inject JS Start'
7676
default_value=''
7777
type='file'
7878
file_types='*.js'
79-
description='A path to a js file that will be executed before any other script is run.'
79+
description='A path to a js file that will be executed before any\nother script is run.'
8080
[[[inject-js-end]]]
8181
display_name='Inject JS End'
8282
default_value=''
8383
type='file'
8484
file_types='*.js'
85-
description='A path to a js file that will be executed after the DOM is loaded.'
85+
description='A path to a js file that will be executed after the\nDOM is loaded.'
8686
[[[snapshot]]]
8787
default_value=''
8888
type='file'
8989
file_types='*.bin'
90-
description='A path to a binary file compiled with snapshot. Used if you don\'t want your code to be exposed.'
90+
description='A path to a binary file compiled with snapshot. Used if you\ndon\'t want your code to be exposed.'
9191
[[[additional_trust_anchors]]]
9292
display_name='Trust Anchors'
9393
default_value=''
9494
type='strings'
95-
description='A list of PEM-encoded certificates. Used as additional root certificates for validation to allow connecting to services using a self-signed certificate.'
95+
description='A list of PEM-encoded certificates. Used as additional root\ncertificates for validation to allow connecting to services using a self-signed certificate.'
9696

9797
[[webkit_settings]]
9898
[[[plugin]]]
@@ -132,13 +132,13 @@ linux_64_dir_prefix = 'node-webkit-v{}-linux-x64'
132132
type='file'
133133
action='set_mac_icon'
134134
file_types='*.png *.jpg *.jpeg *.icns'
135-
description='This icon to be displayed for the Mac Application. Defaults to Window Icon'
135+
description='This icon to be displayed for the Mac Application.\nDefaults to Window Icon'
136136
[[[exe_icon]]]
137137
default_value=''
138138
type='file'
139139
action='set_exe_icon'
140140
file_types='*.png *.jpg *.jpeg'
141-
description='This icon to be displayed for the windows exe of the app. Defaults to Window icon.'
141+
description='This icon to be displayed for the windows exe of the app.\nDefaults to Window icon.'
142142
[[[width]]]
143143
default_value='640'
144144
type='string'
@@ -161,12 +161,12 @@ linux_64_dir_prefix = 'node-webkit-v{}-linux-x64'
161161
display_name='Show Toolbar'
162162
default_value=False
163163
type='check'
164-
description=''
164+
description='Shows the browser toolbar. Deprecated in NW.js >= 0.13.0.'
165165
[[[always-on-top]]]
166166
display_name='Keep on Top'
167167
default_value=False
168168
type='check'
169-
description=''
169+
description='Makes the window always on top of other windows.'
170170
[[[frame]]]
171171
display_name='Window Frame'
172172
default_value=True
@@ -215,7 +215,7 @@ linux_64_dir_prefix = 'node-webkit-v{}-linux-x64'
215215
[[[kiosk_emulation]]]
216216
default_value=False
217217
type='check'
218-
description='Puts the application is kiosk emulation mode. Will automatically check off required settings that will emulate kiosk.'
218+
description='Puts the application is kiosk emulation mode. Will\nautomatically check off required settings that will emulate kiosk.'
219219
check_action='set_kiosk_emulation_options'
220220

221221
[[download_settings]]
@@ -226,6 +226,11 @@ linux_64_dir_prefix = 'node-webkit-v{}-linux-x64'
226226
type='list'
227227
button='Update'
228228
button_callback='update_nw_versions'
229+
[[[sdk_build]]]
230+
display_name='SDK build'
231+
default_value=False
232+
type='check'
233+
description='Downloads the SDK version of NW.js to support devtools by\npressing F12 or ⌘+⌥+i. (Only works on NW.js >= 0.13.0)'
229234
[[[force_download]]]
230235
default_value=False
231236
type='check'
@@ -273,12 +278,12 @@ linux_64_dir_prefix = 'node-webkit-v{}-linux-x64'
273278
min=0
274279
max=9
275280
type='range'
276-
description='Compression to be applied to the executable\'s nwjs binary. 0 is no compression, 9 is maximum. They all use lzma.'
281+
description='Compression to be applied to the executable\'s nwjs binary.\n0 is no compression, 9 is maximum. They all use lzma.'
277282
[[uncompressed_folder]]
278283
display_name='Uncompressed Folder'
279284
type='check'
280285
default_value=False
281-
description='Mac OSX Only! This option makes the resulting app.nw inside the app just a plain folder. This is useful to mitigate startup times and to modify files.'
286+
description='This option makes the resulting app.nw inside the app just a\nplain folder. This is useful to mitigate startup\ntimes and to modify files. (Works on NW.js >= 0.13.0)'
282287

283288

284289
[order]
@@ -296,7 +301,7 @@ linux_64_dir_prefix = 'node-webkit-v{}-linux-x64'
296301
export_setting_order = """['windows-x32', 'windows-x64', 'mac-x32', 'mac-x64', 'linux-x64', 'linux-x32']"""
297302
compression_setting_order = """['nw_compression_level', 'uncompressed_folder']"""
298303

299-
download_setting_order = """['nw_version', 'download_dir',
304+
download_setting_order = """['nw_version', 'sdk_build', 'download_dir',
300305
'force_download']"""
301306

302307
[version_info]

main.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ def __init__(self, width, height, app, parent=None):
211211
self.setStatusBar(status_bar)
212212

213213
self.project_path = ''
214-
#if platform.system() == 'Darwin':
215-
# self.menuBar().setNativeMenuBar(False)
216214
self.project_menu = self.menuBar().addMenu('File')
217215
browse_action = QtGui.QAction('Open Project', self.project_menu,
218216
shortcut=QtGui.QKeySequence.Open,
@@ -692,6 +690,9 @@ def update_progress_bar(self, bytes_read, total_bytes):
692690
def download_file(self, path, setting):
693691
version_file = self.settings['base_url'].format(self.selected_version())
694692

693+
sdk_build_setting = self.get_setting('sdk_build')
694+
sdk_build = sdk_build_setting.value
695+
695696
location = self.get_setting('download_dir').value
696697

697698
versions = re.findall('v(\d+)\.(\d+)\.(\d+)', path)[0]
@@ -700,19 +701,16 @@ def download_file(self, path, setting):
700701
if minor >= 12:
701702
path = path.replace('node-webkit', 'nwjs')
702703

704+
if minor >= 13 and sdk_build:
705+
path = utils.replace_right(path, 'nwjs', 'nwjs-sdk', 1)
706+
703707
self.progress_text = u'Downloading {}'.format(path.replace(version_file, ''))
704708

705709
url = QUrl(path)
706-
file_name = setting.save_file_path(self.selected_version(), location)
710+
file_name = setting.save_file_path(self.selected_version(), location, sdk_build)
707711

708712
archive_exists = QFile.exists(file_name)
709713

710-
#dest_files_exist = False
711-
712-
# for dest_file in setting.dest_files:
713-
# dest_file_path = utils.path_join('files', setting.name, dest_file)
714-
# dest_files_exist &= QFile.exists(dest_file_path)
715-
716714
forced = self.get_setting('force_download').value
717715

718716
if archive_exists and not forced:
@@ -793,8 +791,6 @@ def create_directory_choose(self):
793791
vlayout.setContentsMargins(10, 5, 10, 5)
794792

795793
vlayout.addLayout(title_hbox)
796-
#vlayout.addLayout(input_layout)
797-
#vlayout.addLayout(output_layout)
798794

799795
group_box.setLayout(vlayout)
800796

@@ -883,8 +879,6 @@ def load_project(self, directory):
883879
self.save_project_path(directory)
884880
self.update_recent_files()
885881
self.reset_settings()
886-
#self.input_line.setText(directory)
887-
888882

889883
proj_name = os.path.basename(directory)
890884
self.title_label.setText(proj_name)

utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
DEBUG = False
1515

16+
def replace_right(source, target, replacement, replacements=None):
17+
return replacement.join(source.rsplit(target, replacements))
18+
1619
def is_windows():
1720
return platform.system() == 'Windows'
1821

0 commit comments

Comments
 (0)