def get_pngbytes(icon): """Return the pngbytes of a svg/png icon.""" from HardcodeTray.app import App icon_for_replace = icon.theme icon_extension = icon.theme_ext icon_size = icon.icon_size if icon_extension == 'svg': if icon_size != App.icon_size(): png_bytes = App.svg().to_bin(icon_for_replace, App.icon_size()) else: png_bytes = App.svg().to_bin(icon_for_replace) elif icon_extension == "png": with open(icon_for_replace, 'rb') as png_file: png_bytes = png_file.read() else: png_bytes = None return png_bytes
def get_pngbytes(icon): """Return the pngbytes of a svg/png icon.""" from HardcodeTray.app import App icon_for_replace = icon.theme icon_extension = icon.theme_ext icon_size = icon.icon_size if icon_extension == 'svg': if icon_size != App.icon_size(): png_bytes = App.svg().to_bin(icon_for_replace, App.icon_size()) else: png_bytes = App.svg().to_bin(icon_for_replace) elif icon_extension == "png": with open(icon_for_replace, 'rb') as png_file: png_bytes = png_file.read() else: png_bytes = None return png_bytes
def install_icon(self, icon, icon_path): """Install icon to the current directory.""" ext_orig = icon.orig_ext theme_icon = icon.theme ext_theme = icon.theme_ext icon_size = icon.icon_size output_icon = path.join(str(icon_path), icon.original) # Backup the output_icon if not self.backup_ignore: self.backup.create(output_icon) if ext_theme == ext_orig and theme_icon != output_icon: symlink_file(theme_icon, output_icon) elif ext_theme == "svg" and ext_orig == "png": from HardcodeTray.app import App if icon_size != App.icon_size(): App.svg().to_png(theme_icon, output_icon, App.icon_size()) else: App.svg().to_png(theme_icon, output_icon)
def install_icon(self, icon, icon_path): """Install icon to the current directory.""" ext_orig = icon.orig_ext theme_icon = icon.theme ext_theme = icon.theme_ext icon_size = icon.icon_size output_icon = path.join(str(icon_path), icon.original) # Backup the output_icon if not self.backup_ignore: self.backup.create(output_icon) if ext_theme == ext_orig and theme_icon != output_icon: symlink_file(theme_icon, output_icon) elif ext_theme == "svg" and ext_orig == "png": from HardcodeTray.app import App if icon_size != App.icon_size(): App.svg().to_png(theme_icon, output_icon, App.icon_size()) else: App.svg().to_png(theme_icon, output_icon)
def install_icon(self, icon, icon_path): """Install the icon.""" icon.icon_size = App.icon_size() png_bytes = get_pngbytes(icon) if png_bytes: # Read a target file asar = AsarFile(path.join(str(icon_path), self.binary)) target = B64ElectronApplication.get_real_path(self.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) bytes = file_content.encode() self.set_icon(target, icon_path, bytes, True) else: Logger.error("Icon file was not found.")