summarylogtreecommitdiffstats
path: root/fake_dde-file-manager
blob: 7db5a6b68f82e0122e8891d84cf4d0b754cbbea8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# 7Ji: this is a heavy hack. WeChat, for whatever reason, calls dde-file-manager -> nautilus -> dolphin for
#   any file that it wants to open, instead of a sane dbus call, or xdg-open.
#      Basically, we pretend to be dde-file-manager and hijack the whole call chain in the first place, and
#   convert the not-so-smart dde-file-manager call to a sane dbus-call, or xdg-open if that fails.

_show_item=''
_item=''
for _arg in "$@"; do
    if [[ "${_arg}" == --show-item ]]; then
        _show_item='y'
    else
        [[ -z "${_item}" ]] && _item="${_arg}"
    fi
done

if [[ "${_show_item}" ]]; then
    _path=$(readlink -f -- "${_item}") # Resolve this to absolute path that's same across host / guest
    echo "Fake deepin file manager: dbus-send to open '${_path}' in file manager" 
    if [[ -d "${_path}" ]]; then 
        # WeChat pass both files and folders in the same way, if we use ShowItems for folders, 
        # it would open that folder's parent folder, which is not right.
        _object=ShowFolders
        _target=folders
    else
        _object=ShowItems
        _target=items
    fi
    exec dbus-send --print-reply --dest=org.freedesktop.FileManager1 \
        /org/freedesktop/FileManager1 \
        org.freedesktop.FileManager1."${_object}" \
        array:string:"file://${_path}" \
        string:fake-dde-file-manager-show-"${_target}"
    # We should not fall to here, but add a fallback anyway
    echo "Fake deepin file manager: fallback: xdg-open to show '${_path}' in file manager"
    exec xdg-open "${_path}"
else
    echo "Fake deepin file manager: xdg-open with args $@"
    exec xdg-open "$@"
fi
# At this stage, it's either: dbus-send not found, or xdg-open not found, this should not happen
# In whatever case, bail out
echo "Fake deepin file manager: could not open any thing, original args: $@"
exit 1