Skip to content

Commit 9b72ae9

Browse files
committed
Drop support for NW.js < 0.13.X
The compatibility issues are too much to deal with and the code was getting extremely messy trying to deal with all of the issues. Fixes #153: UPX Compression not compressing dlls Fixes #154: Node-remote resulting in errors
1 parent 9b4f48f commit 9b72ae9

File tree

4 files changed

+150
-180
lines changed

4 files changed

+150
-180
lines changed

command_line.py

Lines changed: 59 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@
4848

4949
COMMAND_LINE = True
5050

51-
NWJS_13_RENAMES = ['always-on-top',
52-
'visible-on-all-workspaces',
53-
'new-instance',
54-
'inject-js-start',
55-
'inject-js-end']
56-
5751
### The following sections are code that needs to be run when importing
5852
### from main.py.
5953

@@ -192,15 +186,7 @@ def save_file_path(self, version, location=None, sdk_build=False):
192186

193187
path = self.full_file_path.format(version)
194188

195-
versions = re.findall('(\d+)\.(\d+)\.(\d+)', version)[0]
196-
197-
minor = int(versions[1])
198-
major = int(versions[0])
199-
200-
if minor >= 12 or major > 0:
201-
path = path.replace('node-webkit', 'nwjs')
202-
203-
if minor >= 13 and sdk_build:
189+
if sdk_build:
204190
path = utils.replace_right(path, 'nwjs', 'nwjs-sdk', 1)
205191

206192
return path
@@ -444,9 +430,14 @@ def get_versions(self):
444430
versions = sorted(union_versions,
445431
key=Version, reverse=True)
446432

447-
if len(versions) > 19:
448-
#Cut off old versions
449-
versions = versions[:-19]
433+
filtered_vers = []
434+
435+
for v in versions:
436+
ver = Version(v)
437+
if ver.major > 0 or (ver.major == 0 and ver.minor >= 13):
438+
filtered_vers.append(v)
439+
440+
versions = filtered_vers
450441

451442
nw_version.values = versions
452443
f = None
@@ -474,18 +465,11 @@ def download_file_with_error_handling(self):
474465
location = self.get_setting('download_dir').value
475466
version = self.selected_version()
476467
path = setting.url.format(version, version)
477-
versions = re.findall('(\d+)\.(\d+)\.(\d+)', version)[0]
478468

479469
sdk_build_setting = self.get_setting('sdk_build')
480470
sdk_build = sdk_build_setting.value
481471

482-
minor = int(versions[1])
483-
major = int(versions[0])
484-
485-
if minor >= 12 or major > 0:
486-
path = path.replace('node-webkit', 'nwjs')
487-
488-
if minor >= 13 and sdk_build:
472+
if sdk_build:
489473
path = utils.replace_right(path, 'nwjs', 'nwjs-sdk', 1)
490474

491475
try:
@@ -533,14 +517,7 @@ def load_package_json(self, json_path=None):
533517

534518
def process_app_settings(self, dic):
535519
"""Process the app settings into the dic"""
536-
versions = self.get_version_tuple()
537-
major_ver = versions[0]
538-
minor_ver = versions[1]
539-
540520
for setting_name, setting in self.settings['app_settings'].items():
541-
if (major_ver > 0 or minor_ver >= 13) and setting_name in NWJS_13_RENAMES:
542-
dic.pop(setting_name, '')
543-
setting_name = setting_name.replace('-', '_')
544521

545522
if setting.value is not None and setting.value != '':
546523
dic[setting_name] = setting.value
@@ -551,16 +528,9 @@ def process_app_settings(self, dic):
551528

552529
def process_window_settings(self, dic):
553530
"""Process the window settings into the dic"""
554-
versions = self.get_version_tuple()
555-
major_ver = versions[0]
556-
minor_ver = versions[1]
557-
558531
for setting_name, setting in self.settings['window_settings'].items():
559-
if major_ver > 0 or minor_ver >= 13 and setting_name in NWJS_13_RENAMES:
560-
dic['window'].pop(setting_name, '')
561-
setting_name = setting_name.replace('-', '_')
562532
if setting.value is not None and setting.value != '':
563-
if 'height' in setting.name or 'width' in setting.name:
533+
if setting.type == 'int':
564534
try:
565535
dic['window'][setting_name] = int(setting.value)
566536
except ValueError:
@@ -683,11 +653,13 @@ def load_from_json(self, json_str):
683653
setting_list.append(setting)
684654
if (setting.type == 'file' or
685655
setting.type == 'string' or
686-
setting.type == 'folder'):
656+
setting.type == 'folder' or
657+
setting.type == 'int'):
687658
val_str = self.convert_val_to_str(new_dic[item])
688659
setting.value = val_str
689660
if setting.type == 'strings':
690661
strs = self.convert_val_to_str(new_dic[item]).split(',')
662+
strs = [x.strip() for x in strs if x]
691663
setting.value = strs
692664
if setting.type == 'check':
693665
setting.value = new_dic[item]
@@ -811,12 +783,6 @@ def get_export_dest(self, ex_setting, output_dir):
811783
"""
812784
export_dest = utils.path_join(output_dir, ex_setting.name)
813785

814-
versions = self.get_version_tuple()
815-
major_ver, minor_ver, _ = versions
816-
817-
if minor_ver >= 12 or major_ver > 0:
818-
export_dest = export_dest.replace('node-webkit', 'nwjs')
819-
820786
return export_dest
821787

822788
def copy_export_files(self, ex_setting, export_dest):
@@ -876,7 +842,7 @@ def replace_plist(self, app_path):
876842

877843
plistlib.writePlist(plist_dict, plist_path)
878844

879-
def process_mac_setting(self, app_loc, export_dest, uncompressed):
845+
def process_mac_setting(self, app_loc, export_dest, ex_setting, uncompressed):
880846
"""Process the Mac settings
881847
882848
Args:
@@ -888,12 +854,9 @@ def process_mac_setting(self, app_loc, export_dest, uncompressed):
888854
app_path = utils.path_join(export_dest,
889855
self.project_name()+'.app')
890856

891-
try:
892-
nw_path = utils.path_join(export_dest, 'nwjs.app')
893-
utils.move(nw_path, app_path)
894-
except IOError:
895-
nw_path = utils.path_join(export_dest, 'node-webkit.app')
896-
utils.move(nw_path, app_path)
857+
nw_path = utils.path_join(export_dest, 'nwjs.app')
858+
self.compress_nw(nw_path, ex_setting)
859+
utils.move(nw_path, app_path)
897860

898861
self.replace_plist(app_path)
899862

@@ -912,20 +875,11 @@ def process_mac_setting(self, app_loc, export_dest, uncompressed):
912875

913876
self.progress_text += '.'
914877

915-
versions = self.get_version_tuple()
916-
major_ver, minor_ver, _ = versions
917-
918-
# If newer version, use different files
919-
if minor_ver >= 13 or major_ver > 0:
920-
self.create_icns_for_app(utils.path_join(resource_path,
921-
'app.icns'))
922-
self.create_icns_for_app(utils.path_join(resource_path,
923-
'document.icns'))
924-
self.replace_localized_app_name(app_path)
925-
926-
else:
927-
self.create_icns_for_app(utils.path_join(resource_path,
928-
'nw.icns'))
878+
self.create_icns_for_app(utils.path_join(resource_path,
879+
'app.icns'))
880+
self.create_icns_for_app(utils.path_join(resource_path,
881+
'document.icns'))
882+
self.replace_localized_app_name(app_path)
929883

930884
self.progress_text += '.'
931885

@@ -952,7 +906,7 @@ def process_win_linux_setting(self, app_loc, export_dest,
952906
ext = '.exe'
953907
self.replace_icon_in_exe(nw_path)
954908

955-
self.compress_nw(nw_path)
909+
self.compress_nw(nw_path, ex_setting)
956910

957911
dest_binary_path = utils.path_join(export_dest,
958912
self.project_name() +
@@ -989,7 +943,8 @@ def process_export_setting(self, ex_setting, output_dir,
989943
self.progress_text += '.'
990944

991945
if 'mac' in ex_setting.name:
992-
self.process_mac_setting(app_loc, export_dest, uncompressed)
946+
self.process_mac_setting(app_loc, export_dest, ex_setting,
947+
uncompressed)
993948
else:
994949
self.process_win_linux_setting(app_loc, export_dest,
995950
ex_setting, uncompressed)
@@ -1068,16 +1023,10 @@ def copy_executable(self, export_path, dest_path,
10681023
"""
10691024
Merge the zip file into the exe and copy it to the destination path
10701025
"""
1071-
versions = self.get_version_tuple()
1072-
major_ver, minor_ver, _ = versions
1073-
1074-
if minor_ver >= 13 or major_ver > 0:
1075-
package_loc = utils.path_join(export_path, 'package.nw')
1076-
if uncompressed:
1077-
utils.copytree(app_loc, package_loc)
1078-
utils.copy(nw_path, dest_path)
1079-
else:
1080-
join_files(dest_path, nw_path, app_loc)
1026+
package_loc = utils.path_join(export_path, 'package.nw')
1027+
if uncompressed:
1028+
utils.copytree(app_loc, package_loc)
1029+
utils.copy(nw_path, dest_path)
10811030
else:
10821031
join_files(dest_path, nw_path, app_loc)
10831032

@@ -1136,7 +1085,7 @@ def make_desktop_file(self, nw_path, export_dest):
11361085

11371086
os.chmod(dfile_path, 0o755)
11381087

1139-
def compress_nw(self, nw_path):
1088+
def compress_nw(self, nw_path, ex_setting):
11401089
"""Compress the nw file using upx"""
11411090
compression = self.get_setting('nw_compression_level')
11421091

@@ -1163,7 +1112,25 @@ def compress_nw(self, nw_path):
11631112
upx_bin = upx_version
11641113
os.chmod(upx_bin, 0o755)
11651114

1166-
cmd = [upx_bin, '--lzma', u'-{}'.format(compression.value), nw_path]
1115+
cmd = [upx_bin, '--lzma', u'-{}'.format(compression.value)]
1116+
1117+
if 'windows' in ex_setting.name:
1118+
path = os.path.join(os.path.dirname(nw_path), '*.dll')
1119+
cmd.extend(glob.glob(path))
1120+
elif 'linux' in ex_setting.name:
1121+
path = os.path.join(os.path.dirname(nw_path), 'lib', '*.so')
1122+
cmd.extend(glob.glob(path))
1123+
elif 'mac' in ex_setting.name:
1124+
dylib_path = utils.path_join(
1125+
nw_path,
1126+
'Contents',
1127+
'Versions',
1128+
'**',
1129+
'nwjs Framework.framework',
1130+
)
1131+
cmd.extend(glob.glob(os.path.join(dylib_path, 'nwjs Framework')))
1132+
path = os.path.join(dylib_path, '*.dylib')
1133+
cmd.extend(glob.glob(path))
11671134

11681135
if platform.system() == 'Windows':
11691136
startupinfo = subprocess.STARTUPINFO()
@@ -1190,6 +1157,11 @@ def compress_nw(self, nw_path):
11901157
time.sleep(2)
11911158

11921159
output, err = proc.communicate()
1160+
if err:
1161+
args = ex_setting.name, platform.system(), ex_setting.name
1162+
self.output_err = (
1163+
'Cannot compress files for {} on {}!\n'
1164+
'Run Web2Exe on {} to compress successfully.').format(args)
11931165

11941166
def remove_readonly(self, action, name, exc):
11951167
"""Try to remove readonly files"""
@@ -1430,13 +1402,7 @@ def download_file(self, path, setting):
14301402
sdk_build_setting = self.get_setting('sdk_build')
14311403
sdk_build = sdk_build_setting.value
14321404

1433-
versions = self.get_version_tuple()
1434-
major, minor, _ = versions
1435-
1436-
if minor >= 12 or major > 0:
1437-
path = path.replace('node-webkit', 'nwjs')
1438-
1439-
if minor >= 13 and sdk_build:
1405+
if sdk_build:
14401406
path = utils.replace_right(path, 'nwjs', 'nwjs-sdk', 1)
14411407

14421408
url = path
@@ -1656,6 +1622,9 @@ def my_excepthook(type_, value, tback):
16561622
if not args.title:
16571623
args.title = command_base.project_name()
16581624

1625+
if not args.id:
1626+
args.id = command_base.project_name()
1627+
16591628
for name, val in args._get_kwargs():
16601629
if callable(val):
16611630
val = val()

0 commit comments

Comments
 (0)