mirror of
https://github.com/element-hq/element-desktop.git
synced 2025-12-25 00:28:43 -05:00
Compare commits
3 Commits
develop
...
t3chguy/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bc6f4dafa | ||
|
|
84ffc7e2e6 | ||
|
|
344d473e9b |
20
src/tray.ts
20
src/tray.ts
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { app, Tray, Menu, nativeImage } from "electron";
|
||||
import { app, Tray, Menu, nativeImage, NativeImage } from "electron";
|
||||
import pngToIco from "png-to-ico";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
@@ -50,6 +50,12 @@ interface IConfig {
|
||||
brand: string;
|
||||
}
|
||||
|
||||
async function convertToIco(img: NativeImage): Promise<NativeImage> {
|
||||
const icoPath = path.join(app.getPath("temp"), "win32_element_icon.ico");
|
||||
fs.writeFileSync(icoPath, await pngToIco(img.toPNG()));
|
||||
return nativeImage.createFromPath(icoPath);
|
||||
}
|
||||
|
||||
export function create(config: IConfig): void {
|
||||
// no trays on darwin
|
||||
if (process.platform === "darwin" || trayIcon) return;
|
||||
@@ -62,7 +68,7 @@ export function create(config: IConfig): void {
|
||||
|
||||
let lastFavicon: string | null = null;
|
||||
global.mainWindow?.webContents.on("page-favicon-updated", async function (ev, favicons) {
|
||||
if (!favicons || favicons.length <= 0 || !favicons[0].startsWith("data:")) {
|
||||
if (!favicons?.[0]?.startsWith("data:")) {
|
||||
if (lastFavicon !== null) {
|
||||
global.mainWindow?.setIcon(defaultIcon);
|
||||
trayIcon?.setImage(defaultIcon);
|
||||
@@ -80,16 +86,18 @@ export function create(config: IConfig): void {
|
||||
// Windows likes ico's too much.
|
||||
if (process.platform === "win32") {
|
||||
try {
|
||||
const icoPath = path.join(app.getPath("temp"), "win32_element_icon.ico");
|
||||
fs.writeFileSync(icoPath, await pngToIco(newFavicon.toPNG()));
|
||||
newFavicon = nativeImage.createFromPath(icoPath);
|
||||
newFavicon = await convertToIco(newFavicon);
|
||||
} catch (e) {
|
||||
console.error("Failed to make win32 ico", e);
|
||||
}
|
||||
}
|
||||
|
||||
trayIcon?.setImage(newFavicon);
|
||||
global.mainWindow?.setIcon(newFavicon);
|
||||
|
||||
// Don't set the main window icon on Windows as we call Navigator::setAppBadge to do it for us
|
||||
if (process.platform !== "win32") {
|
||||
global.mainWindow?.setIcon(newFavicon);
|
||||
}
|
||||
});
|
||||
|
||||
global.mainWindow?.webContents.on("page-title-updated", function (ev, title) {
|
||||
|
||||
Reference in New Issue
Block a user