Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Base64 hardcoded icons in binary files #653

Merged
merged 9 commits into from
Aug 5, 2020
Merged
1 change: 1 addition & 0 deletions HardcodeTray/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class ApplicationType:
Different Applications Type
"""
ELECTRON = "ElectronApplication"
B64ELECTRON = "B64ElectronApplication"
ZIP = "ZipApplication"
PAK = "PakApplication"
NWJS = "NWJSApplication"
Expand Down
67 changes: 67 additions & 0 deletions HardcodeTray/modules/applications/b64electron.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
Fixes Hardcoded tray icons in Linux.

Author : Ivo Šmerek (ivo.smerek@gmail.com)
Contributors : Bilal Elmoussaoui, Alexey Varfolomeev
Website : https://github.com/bil-elmoussaoui/Hardcode-Tray
Licence : The script is released under GPL, uses a modified script
form Chromium project released under BSD license
This file is part of Hardcode-Tray.
Hardcode-Tray is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Hardcode-Tray is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Hardcode-Tray. If not, see <http://www.gnu.org/licenses/>.
"""
from base64 import b64encode
from glob import glob
from os import path, system
from fileinput import FileInput

from HardcodeTray.app import App
from HardcodeTray.modules.applications.electron import ElectronApplication
from HardcodeTray.modules.applications.helpers.asar import AsarFile
from HardcodeTray.modules.log import Logger
from HardcodeTray.utils import get_pngbytes


class B64ElectronApplication(ElectronApplication):
"""Electron application with Base64 hardcoded icons."""

def __init__(self, parser):
"""Use the parent class, Application, modify only the (re)install."""
ElectronApplication.__init__(self, parser)

def install_icon(self, icon, icon_path):
"""Install the icon."""
icon.icon_size = App.icon_size()

png_bytes = get_pngbytes(icon)

if png_bytes:
binary_file = path.join(str(icon_path), self.binary)
asar = AsarFile(binary_file)
target = B64ElectronApplication.get_real_path(self.file)
# Read a target file
file_content = asar.read_file(target).decode()
# Create new base64 binary file
base64_icon = b64encode(App.svg().to_bin(icon.theme, icon.icon_size, icon.icon_size))
# Build new icon
new_icon = "data:image/png;base64," + base64_icon.decode()
# Replace the original icon with newly built one
file_content = file_content.replace(icon.original, new_icon)
# Write changed file
asar.write(target, file_content.encode())
else:
Logger.error("Icon file was not found.")

def revert_icon(self, icon, icon_path):
"""Revert to the original icon."""
bilelmoussaoui marked this conversation as resolved.
Show resolved Hide resolved
# I don't know what is the best way to handle backup here.
# Maybe backup whole app.asar file?
Logger.error("Backup file of {0} was not found".format(self.name))
21 changes: 20 additions & 1 deletion HardcodeTray/modules/applications/helpers/asar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Fixes Hardcoded tray icons in Linux.

Author : Bilal Elmoussaoui (bil.elmoussaoui@gmail.com)
Contributors : Andreas Angerer, Joshua Fogg
Contributors : Andreas Angerer, Joshua Fogg, Ivo Šmerek
Website : https://github.com/bil-elmoussaoui/Hardcode-Tray
Licence : The script is released under GPL, uses a modified script
form Chromium project released under BSD license
Expand Down Expand Up @@ -119,3 +119,22 @@ def write(self, icon, pngbytes):
asarfile = open(self._asar_file, 'wb')
asarfile.write(asar_content)
asarfile.close()

def read_file(self, path):
"""Read a file in asar archive."""
self._keys = path.split("/")

fileinfo = get_from_dict(self._header, self._keys)

if (not isinstance(fileinfo, dict)
or "offset" not in fileinfo.keys()):
return

offset0 = int(fileinfo['offset'])
offset = offset0 + self._offset
size = int(fileinfo['size'])

with open(self._asar_file, 'rb') as asarfile:
asar = asarfile.read()

return asar[offset: offset + size]
22 changes: 22 additions & 0 deletions data/database/nozbe.json

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions data/database/slack.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "Slack",
"app_path": [
"/usr/share/slack/",
"/usr/lib/slack/"
],
"icons_path": [
"/usr/share/slack/resources/",
"/usr/lib/slack/resources/"
],
"binary": "app.asar",
"script": "b64electron",
"file": "dist/main.bundle.js",
"icons": {
"highlight": {
"original": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAAXNSR0IArs4c6QAABBRJREFUOBGNlW1IW2cUx59c82KTNW0jNE2IXaadYytjhuLcmLF2MEM/DMqcjso6QSuI4FBaSj8UJkxmy1g/DBEGymQo2wqDzRfmW0GHK8R+sG6LRV1CbGPQCpqXapKbm3v3P1dviRplB355Xu5z/vd5zjn3CWOHWxYeHweqtGVa9I1p44zddIf0BST4PngHUD8GRoAJOAH5LYOfQQTsM27fzPaE02g0vjc5Ofmu3++/3NfXdxbTl0Bpf3//Gx6P52JRUVEuxhe3l///32uDg4P3pDRraWm5W1xc/CWmRJoeGxv7FXI3DpLMtGOa01ut1lPpTiUlJRabzabGnBy+l2Do05iM5naFNZOwiEXLXV1dbkEQePIiy8qiUO8z8v8I3NzhY7T0whdvpAUOYN+Z03Z2dm663e47lZWVJo1Gw42Ojq4j7nvV1Q6Ho7Cjo6OY4zhVc3OzHj6U4G7lKB/igaOxsdFgsVh0ePDCUqmUODw8HJqYmBAqKir2CrOhoaHP4PMyOVBizWZzF7p2Gh8BrVNTU7+n5WpvN1VXV3cHwu1YJ7W3t0vl5eVPcJI/cTLJ5/Mp60WcqhV652jH8i52koFhRuN0Ot2xgYGBt7xer4h4c2uBoF5Kifbu7m7W09PDamtrmdPpfBSJyGW9omTyU1TBmba2tlyTyaTfK434hrGzD1QqVfZt+3njZWvpkZPZNk5gvPR066n4xep47H7YHw+FQj6E7mv4/6IIv4JBDURZWVmZFgIqJCERCAQYVRXP865kMnn6wZtXcwpzCnflYHsTKukb30/Pby39EcWY6vtzJRnVTU1N5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