Skip to content

Commit

Permalink
Discover dicts directly storing data in Contents/Body.data
Browse files Browse the repository at this point in the history
While all dictionaries that come bundled with macOS
store the `Body.data` file in `Contents/Resources` folder,
https://agiletortoise.com/terminology/mac/ stores it
directly in the `Contents` folder.

With this change, we make sure to handle that case as
well.

At the moment, importing the Terminology dictionary still
leads to visual glitches in the previews, which we may fix
if future patches.
  • Loading branch information
mr-pennyworth committed Feb 23, 2024
1 parent 1a2a057 commit 3be9a6c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ Subsequent searches should be snappy
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>0.2.7</string>
<string>0.2.8</string>
<key>webaddress</key>
<string>https://github.com/mr-pennyworth/alfred-better-dictionaries</string>
</dict>
Expand Down
16 changes: 14 additions & 2 deletions pyapp/BetterDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,21 @@ def all_dict_paths():
dict_globs = [
'/System/Library/AssetsV2/**/*.dictionary',
'/Library/Dictionaries/**/*.dictionary',
f'{HOME}/Library/Dictionaries/**/*.dictionary'
f'{HOME}/Library/Dictionaries/**/*.dictionary',
]
for dict_glob in dict_globs:
dict_paths.extend(glob.glob(dict_glob, recursive=True))
return [
dict_path for dict_path
in dict_paths
if os.path.exists(f'{dict_path}/Contents/Resources/Body.data')
if any(map(os.path.exists, [
f'{dict_path}/Contents/Resources/Body.data',
# While all dictionaries that come bundled with macOS store Body.data
# in the Contents/Resources folder,
# https://agiletortoise.com/terminology/mac/ stores the Body.data
# directly in the Contents folder.
f'{dict_path}/Contents/Body.data',
]))
]


Expand Down Expand Up @@ -311,6 +318,11 @@ def import_dict(dict_path, import_base_dir):
dict_name = get_dict_name(info)

data_path = f'{dict_path}/Contents/Resources/Body.data'
if not os.path.exists(data_path):
# https://agiletortoise.com/terminology/mac/ stores the Body.data directly
# in the Contents folder (and not in Contents/Resources folder).
data_path = f'{dict_path}/Contents/Body.data'

dest_dir = f'{import_base_dir}/{dict_id}'
dest_html_dir = f'{dest_dir}/html'
db_path = f'{import_base_dir}/db'
Expand Down

0 comments on commit 3be9a6c

Please sign in to comment.