bilelmoussaoui / Hardcode-Tray

Fixes Hardcoded tray icons in Linux
Other
859 stars 63 forks source link

Mattermost #704

Closed rauldipeas closed 2 years ago

rauldipeas commented 2 years ago

image

rauldipeas commented 2 years ago

This needs an update, i'm trying to do it here, but no lucky...

{
    "name": "Mattermost",
    "app_path": [
        "/opt/Mattermost/",
        "/usr/lib/mattermost/"
    ],
    "icons_path": [
        "/opt/Mattermost/resources/",
        "/usr/lib/mattermost/resources/"
    ],
    "binary": "app.asar",
    "script": "electron",
    "icons": {
        "tray-light": {
            "original": "assets/linux/top_bar_light_16.png",
            "theme": "mattermost-tray"
        },
        "tray-light-unread": {
            "original": "assets/linux/top_bar_unread_light_16.png",
            "theme": "mattermost-unread"
        },
        "tray-light-mention": {
            "original": "assets/linux/top_bar_mention_light_16.png",
            "theme": "mattermost-mention"
        },
        "tray-light@2x": {
            "original": "assets/linux/top_bar_light_16@2x.png",
            "theme": "mattermost-tray"
        },
        "tray-light@2x-unread": {
            "original": "assets/linux/top_bar_unread_light_16@2x.png",
            "theme": "mattermost-unread"
        },
        "tray-light@2x-mention": {
            "original": "assets/linux/top_bar_mention_light_16@2x.png",
            "theme": "mattermost-mention"
        },
        "tray-dark": {
            "original": "assets/linux/top_bar_dark_16.png",
            "theme": "mattermost-tray"
        },
        "tray-dark-unread": {
            "original": "assets/linux/top_bar_unread_dark_16.png",
            "theme": "mattermost-unread"
        },
        "tray-dark-mention": {
            "original": "assets/linux/top_bar_mention_dark_16.png",
            "theme": "mattermost-mention"
        },
        "tray-dark@2x": {
            "original": "assets/linux/top_bar_dark_16@2x.png",
            "theme": "mattermost-tray"
        },
        "tray-dark@2x-unread": {
            "original": "assets/linux/top_bar_unread_dark_16@2x.png",
            "theme": "mattermost-unread"
        },
        "tray-dark@2x-mention": {
            "original": "assets/linux/top_bar_mention_dark_16@2x.png",
            "theme": "mattermost-mention"
        }
    }
}
 rauldipeas@IdeaPad-320  ~  sudo hardcode-tray --apply --only mattermost.electron
Welcome to Hardcode-Tray!
Hardcode-Tray replaces some icons on the binary files of some applications. 
Please close all the running applications before running Hardcode-Tray script.
Desktop Environment: Other
Scaling Factor: 1
Icon Size: 24
Icon Theme: Luv
Conversion Tool: RSVGConvert
To Do: Mattermost.Electron
Applying now..

Traceback (most recent call last):
  File "/usr/bin/hardcode-tray", line 121, in <module>
    App.execute()
  File "/usr/lib/python3.7/site-packages/HardcodeTray/app.py", line 120, in execute
    delta = app.do_action(action)
  File "/usr/lib/python3.7/site-packages/HardcodeTray/modules/applications/application.py", line 148, in do_action
    self.install()
  File "/usr/lib/python3.7/site-packages/HardcodeTray/decorators.py", line 58, in wrapper
    func(app)
  File "/usr/lib/python3.7/site-packages/HardcodeTray/modules/applications/application.py", line 96, in install
    self.execute(Action.APPLY)
  File "/usr/lib/python3.7/site-packages/HardcodeTray/modules/applications/helpers/binary.py", line 50, in execute
    self.install_icon(icon, icon_path)
  File "/usr/lib/python3.7/site-packages/HardcodeTray/modules/applications/electron.py", line 41, in install_icon
    self.set_icon(icon, icon_path, png_bytes, True)
  File "/usr/lib/python3.7/site-packages/HardcodeTray/modules/applications/electron.py", line 66, in set_icon
    asar.write(icon_to_replace, png_bytes)
  File "/usr/lib/python3.7/site-packages/HardcodeTray/modules/applications/helpers/asar.py", line 106, in write
    new_files = change_dict_vals(self._header, sizediff, offset0)
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in change_dict_vals
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in <dictcomp>
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in change_dict_vals
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in <dictcomp>
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in change_dict_vals
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in <dictcomp>
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in change_dict_vals
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in <dictcomp>
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in change_dict_vals
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in <dictcomp>
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in change_dict_vals
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in <dictcomp>
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in change_dict_vals
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in <dictcomp>
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in change_dict_vals
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in <dictcomp>
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in change_dict_vals
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 244, in <dictcomp>
    d2 = {k: change_dict_vals(v, sizediff, offset) for k, v in d.items()}
  File "/usr/lib/python3.7/site-packages/HardcodeTray/utils.py", line 245, in change_dict_vals
    if d2.get('offset') and int(d2.get('offset')) > offset:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'dict'
rauldipeas commented 2 years ago

image

varlesh commented 2 years ago

Current release 4.7.2 and i'm not seen your icons on this location: Screenshot_20210922_040427

varlesh commented 2 years ago

assets: Screenshot_20210922_040639

varlesh commented 2 years ago

ough, it's 5.0.0 RC

rauldipeas commented 2 years ago

I'm on version 5.0.0-rc1-13336.

varlesh commented 2 years ago

similar bug #646

varlesh commented 2 years ago

downgrade to 4.7.2 i don't know how solve this

rauldipeas commented 2 years ago

I'm fixed Gitify manually, with a script that replace files.

varlesh commented 2 years ago

and #637 to

rauldipeas commented 2 years ago

I'm fixing Gitify like this...

npx asar e /opt/Gitify/resources/app.asar app
rsvg-convert /usr/share/icons/Papirus/24x24/panel/gitify-tray-active.svg -o app/assets/images/tray-active.png 
rsvg-convert /usr/share/icons/Papirus/24x24@2x/panel/gitify-tray-active.svg -w 48 -o app/assets/images/tray-active@2x.png 
rsvg-convert /usr/share/icons/Papirus/24x24/panel/gitify-tray.svg -o app/assets/images/tray-idleTemplate.png 
rsvg-convert /usr/share/icons/Papirus/24x24@2x/panel/gitify-tray.svg -w 48 -o app/assets/images/tray-idleTemplate@2x.png
npx asar p app app.asar
sudo cp -rfv app.asar /opt/Gitify/resources/app.asar
varlesh commented 2 years ago

@acarasimon96 Timothy you know python, maybe you can help solve this error? I think asar module don't get header bytes for right work on some electron-apps. TypeError: int() argument must be a string, a bytes-like object or a number, not 'dict'

For test you can use this app. Extract archives and found resources/app.asar file. This worked: https://releases.mattermost.com/desktop/4.7.2/mattermost-desktop-4.7.2-linux-x64.tar.gz This not worked: https://releases.mattermost.com/desktop/5.0.0-rc1/mattermost-desktop-5.0.0-rc1-linux-x64.tar.gz

acarasimon96 commented 2 years ago

I just successfully ran Hardcode Tray Git version on Mattermost desktop 5.0.0-rc1, but I'm not getting a TypeError on my end. I'm not getting any useful hints either in the debug logs.

It appears that the tray icons in app.asar matches those shown in this comment by the issue creator. If Hardcode Tray really did replace the icons as expected, the icons between light and dark variants in that same directory would be identical.

image

For comparison, here are the icons from Papirus that the script should've used to replace the above: image

I don't think this looks like an easy fix for me, but it's possible to get it done. This will take a couple days for me to find out the cause and implement a fix since I also have school, chores at home, and other interests to deal with. I apologize for any inconvenience that may arise out of my life situation.

Also, thank you for the unexpected ping, @varlesh. I'm thrilled to be able to help you out with this issue!

Edit: I forgot to upload the debug logfile, so here you go: 2021-09-21 19:36:04.log

rauldipeas commented 2 years ago

I'm temporarily using this solution to fix tray icons on my apt repository. https://gitlab.com/myawesomedistro/madrepo/-/blob/main/scripts/mkpkg/mattermost.sh

varlesh commented 2 years ago

@acarasimon96 Thanks for your efforts... it's only your desire, I do not insist

varlesh commented 2 years ago

I just successfully ran Hardcode Tray Git version on Mattermost desktop 5.0.0-rc1, but I'm not getting a TypeError on my end. I'm not getting any useful hints either in the debug logs

for 5.0.0 RC need use this config

acarasimon96 commented 2 years ago

Oh, I didn't realize to do that first. Now I'm getting the same exact error @rauldipeas got.

acarasimon96 commented 2 years ago

I was able to fix the crash, and it was a bit easier than I thought. It was caused by a directory that is literally called "offset" inside app.asar. I changed the code to where it makes sure that the value for "offset" is a string (that is, the real offset value of a file) before recalculating it. However, for some weird reason, I still couldn't get the script to replace the mention and unread icons. I would consider this issue solved once that new bug gets fixed and no other side effects come out of that.

varlesh commented 2 years ago

@acarasimon96 glad to hear about success On logs backup only 16px and 16@2x icons:

[DEBUG] 2021-09-23 06:22:43 Create new backup folder for Mattermost
[DEBUG] 2021-09-23 06:22:43 Creating directory: /home/alex/.config/Hardcode-Tray/Mattermost/2021-09-23 06:22:43/
[DEBUG] 2021-09-23 06:22:43 Executing command: rsvg-convert -f png -o /tmp/tmp9jdsnztd -w 22 -h 22 /usr/share/icons/Papirus-Dark/22x22/panel/mattermost-tray.svg
[DEBUG] 2021-09-23 06:22:44 Backup file: /tmp/files|assets|files|linux|files|top_bar_light_16.png to: /home/alex/.config/Hardcode-Tray/Mattermost/2021-09-23 06:22:43/files|assets|files|linux|files|top_bar_light_16.png
[DEBUG] 2021-09-23 06:22:44 Executing command: rsvg-convert -f png -o /tmp/tmpx9blhr3j -w 22 -h 22 /usr/share/icons/Papirus-Dark/22x22/panel/mattermost-unread.svg
[DEBUG] 2021-09-23 06:22:44 Executing command: rsvg-convert -f png -o /tmp/tmpylubzicr -w 22 -h 22 /usr/share/icons/Papirus-Dark/22x22/panel/mattermost-mention.svg
[DEBUG] 2021-09-23 06:22:44 Executing command: rsvg-convert -f png -o /tmp/tmp3pcydgli -w 22 -h 22 /usr/share/icons/Papirus-Dark/22x22/panel/mattermost-tray.svg
[DEBUG] 2021-09-23 06:22:44 Backup file: /tmp/files|assets|files|linux|files|top_bar_light_16@2x.png to: /home/alex/.config/Hardcode-Tray/Mattermost/2021-09-23 06:22:43/files|assets|files|linux|files|top_bar_light_16@2x.png
[DEBUG] 2021-09-23 06:22:44 Executing command: rsvg-convert -f png -o /tmp/tmphyomnemk -w 22 -h 22 /usr/share/icons/Papirus-Dark/22x22/panel/mattermost-unread.svg
[DEBUG] 2021-09-23 06:22:44 Executing command: rsvg-convert -f png -o /tmp/tmpdc8i4nab -w 22 -h 22 /usr/share/icons/Papirus-Dark/22x22/panel/mattermost-mention.svg
[DEBUG] 2021-09-23 06:22:44 Executing command: rsvg-convert -f png -o /tmp/tmpaq7hwufl -w 22 -h 22 /usr/share/icons/Papirus-Dark/22x22/panel/mattermost-tray.svg
[DEBUG] 2021-09-23 06:22:44 Backup file: /tmp/files|assets|files|linux|files|top_bar_dark_16.png to: /home/alex/.config/Hardcode-Tray/Mattermost/2021-09-23 06:22:43/files|assets|files|linux|files|top_bar_dark_16.png
[DEBUG] 2021-09-23 06:22:44 Executing command: rsvg-convert -f png -o /tmp/tmp3wgx1tc2 -w 22 -h 22 /usr/share/icons/Papirus-Dark/22x22/panel/mattermost-unread.svg
[DEBUG] 2021-09-23 06:22:44 Executing command: rsvg-convert -f png -o /tmp/tmp_i3kucko -w 22 -h 22 /usr/share/icons/Papirus-Dark/22x22/panel/mattermost-mention.svg
[DEBUG] 2021-09-23 06:22:44 Executing command: rsvg-convert -f png -o /tmp/tmpxeukqnhp -w 22 -h 22 /usr/share/icons/Papirus-Dark/22x22/panel/mattermost-tray.svg
[DEBUG] 2021-09-23 06:22:44 Backup file: /tmp/files|assets|files|linux|files|top_bar_dark_16@2x.png to: /home/alex/.config/Hardcode-Tray/Mattermost/2021-09-23 06:22:43/files|assets|files|linux|files|top_bar_dark_16@2x.png
[DEBUG] 2021-09-23 06:22:44 Executing command: rsvg-convert -f png -o /tmp/tmpwmyv1ufh -w 22 -h 22 /usr/share/icons/Papirus-Dark/22x22/panel/mattermost-unread.svg
[DEBUG] 2021-09-23 06:22:44 Executing command: rsvg-convert -f png -o /tmp/tmptszjzw7e -w 22 -h 22 /usr/share/icons/Papirus-Dark/22x22/panel/mattermost-mention.svg
varlesh commented 2 years ago

Other files not backuped Screenshot_20210923_063615

acarasimon96 commented 2 years ago

I still couldn't get the script to replace the mention and unread icons. I would consider this issue solved once that new bug gets fixed and no other side effects come out of that.

On logs backup only 16px and 16@2x icons

It turns out that a few typos in [this comment with the modified mattermost.electron.json]() is what prevented the unread and mentioned tray icons from being replaced or backed up. I moved mention and unread after light or dark in the JSON, depending on the target filename, and it worked!

Here is the corrected mattermost.electron.json file ```json { "name": "Mattermost", "app_path": [ "/opt/Mattermost/", "/usr/lib/mattermost/" ], "icons_path": [ "/opt/Mattermost/resources/", "/usr/lib/mattermost/resources/" ], "binary": "app.asar", "script": "electron", "icons": { "tray-light": { "original": "assets/linux/top_bar_light_16.png", "theme": "mattermost-tray" }, "tray-light-unread": { "original": "assets/linux/top_bar_light_unread_16.png", "theme": "mattermost-unread" }, "tray-light-mention": { "original": "assets/linux/top_bar_light_mention_16.png", "theme": "mattermost-mention" }, "tray-light@2x": { "original": "assets/linux/top_bar_light_16@2x.png", "theme": "mattermost-tray" }, "tray-light@2x-unread": { "original": "assets/linux/top_bar_light_unread_16@2x.png", "theme": "mattermost-unread" }, "tray-light@2x-mention": { "original": "assets/linux/top_bar_light_mention_16@2x.png", "theme": "mattermost-mention" }, "tray-dark": { "original": "assets/linux/top_bar_dark_16.png", "theme": "mattermost-tray" }, "tray-dark-unread": { "original": "assets/linux/top_bar_dark_unread_16.png", "theme": "mattermost-unread" }, "tray-dark-mention": { "original": "assets/linux/top_bar_dark_mention_16.png", "theme": "mattermost-mention" }, "tray-dark@2x": { "original": "assets/linux/top_bar_dark_16@2x.png", "theme": "mattermost-tray" }, "tray-dark@2x-unread": { "original": "assets/linux/top_bar_dark_unread_16@2x.png", "theme": "mattermost-unread" }, "tray-dark@2x-mention": { "original": "assets/linux/top_bar_dark_mention_16@2x.png", "theme": "mattermost-mention" } } } ```

And below is the final result with the icons properly replaced image

P.S. @rauldipeas, please remember to submit a new PR containing the new JSON file.

varlesh commented 2 years ago

also i'm extract patched asar and selected files - it's Papirus files 100 % Screenshot_20210923_063810

varlesh commented 2 years ago

@acarasimon96 Congratulations, you are cool!!! :1st_place_medal: I can merge PR?

acarasimon96 commented 2 years ago

Sure, go ahead, but make sure you test the PR first on your system before merging. I'm glad I was able to help out. 😊

varlesh commented 2 years ago

@acarasimon96 Big thx!!! I'm also test it with other problem apps Franz #637 & Gitify #646 and merged

varlesh commented 2 years ago

P.S. @rauldipeas, please remember to submit a new PR containing the new JSON file.

I'm doing this

rauldipeas commented 2 years ago

Thank you so much @acarasimon96 and @varlesh, this fix help-me so much!

varlesh commented 2 years ago

Franz & Gitify fixed too!

steakscience commented 2 years ago

I'm on Mattermost 5.0.4, and hardcode-tray doesn't detect it. Does it work for others?

rauldipeas commented 2 years ago

image

steakscience commented 2 years ago

@rauldipeas Interesting... I do have app.asar in /usr/lib (same as this) but I don't know why it's not detecting.

It is detecting my apps just fine