Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion element.io/nightly/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@
"feature_spotlight": true,
"feature_video_rooms": true
},
"map_style_url": "https://api.maptiler.com/maps/streets/style.json?key=fU3vlMsMn4Jb6dnEIFsx"
"map_style_url": "https://api.maptiler.com/maps/streets/style.json?key=fU3vlMsMn4Jb6dnEIFsx",
"tray_icons": {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't be supplying default values in the config. This is because the code needs to handle a case where the value isn't supplied, and we pick sensible defaults for everything. Whenever we can, we force ourselves to test this by not specifying them in the production configs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I reading this right if with this change, you now consider this resolved?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, it's resolved when the config.json files for nightly and release aren't modified :p

}
3 changes: 2 additions & 1 deletion element.io/release/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
"apiHost": "https://posthog.element.io"
},
"privacy_policy_url": "https://element.io/cookie-policy",
"map_style_url": "https://api.maptiler.com/maps/streets/style.json?key=fU3vlMsMn4Jb6dnEIFsx"
"map_style_url": "https://api.maptiler.com/maps/streets/style.json?key=fU3vlMsMn4Jb6dnEIFsx",
"tray_icons": {}
}
3 changes: 1 addition & 2 deletions src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ declare global {
launcher: AutoLaunch;
vectorConfig: Record<string, any>;
trayConfig: {
// eslint-disable-next-line camelcase
icon_path: string;
brand: string;
iconPath: string;
};
store: Store<{
warnBeforeExit?: boolean;
Expand Down
20 changes: 12 additions & 8 deletions src/electron-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ const argv = minimist(process.argv, {
// async to are initialised in setupGlobals()
let asarPath: string;
let resPath: string;
let iconPath: string;

if (argv["help"]) {
console.log("Options:");
Expand Down Expand Up @@ -192,17 +191,22 @@ async function setupGlobals(): Promise<void> {
}

// The tray icon
// It's important to call `path.join` so we don't end up with the packaged asar in the final path.
const iconFile = `element.${process.platform === 'win32' ? 'ico' : 'png'}`;
iconPath = path.join(resPath, "img", iconFile);
// It's important to call `path.join` for the bundled assets so we don't end up with the packaged asar in the final path.
const iconPath = process.platform === 'win32'
? (global.vectorConfig?.tray_icons?.ico || path.join(resPath, 'img', 'element.ico'))
: (global.vectorConfig?.tray_icons?.png || path.join(resPath, 'img', 'element.png'));

global.trayConfig = {
icon_path: iconPath,
brand: global.vectorConfig.brand || 'Element',
};
iconPath,
allowWebIconOverride: !!(
process.platform === 'win32' && global.vectorConfig?.tray_icons?.ico || global.vectorConfig?.tray_icons?.png
),
} as tray.IConfig;

// launcher
global.launcher = new AutoLaunch({
name: global.vectorConfig.brand || 'Element',
name: global.trayConfig.brand,
isHidden: true,
mac: {
useLaunchAgent: true,
Expand Down Expand Up @@ -418,7 +422,7 @@ app.on('ready', async () => {
// https://www.electronjs.org/docs/faq#the-font-looks-blurry-what-is-this-and-what-can-i-do
backgroundColor: '#fff',

icon: iconPath,
icon: global.trayConfig.iconPath,
show: false,
autoHideMenuBar: global.store.get('autoHideMenuBar', true),

Expand Down
21 changes: 13 additions & 8 deletions src/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,32 @@ function toggleWin(): void {
}
}

interface IConfig {
icon_path: string; // eslint-disable-line camelcase
export interface IConfig {
allowWebIconOverride: boolean;
iconPath: string;
brand: string;
}

export function create(config: IConfig): void {
// no trays on darwin
if (process.platform === 'darwin' || trayIcon) return;
const defaultIcon = nativeImage.createFromPath(config.icon_path);
const defaultIcon = nativeImage.createFromPath(config.iconPath);

trayIcon = new Tray(defaultIcon);
trayIcon.setToolTip(config.brand);
initApplicationMenu();
trayIcon.on('click', toggleWin);

let lastFavicon = null;
global.mainWindow.webContents.on('page-favicon-updated', async function(ev, favicons) {
global.mainWindow.webContents.on('page-title-updated', (_ev: Event, title: string) => {
trayIcon.setToolTip(title);
});

if (!config.allowWebIconOverride) {
return;
}

global.mainWindow.webContents.on('page-favicon-updated', async (_ev: Event, favicons: string[]) => {
if (!favicons || favicons.length <= 0 || !favicons[0].startsWith('data:')) {
if (lastFavicon !== null) {
global.mainWindow.setIcon(defaultIcon);
Expand Down Expand Up @@ -91,10 +100,6 @@ export function create(config: IConfig): void {
trayIcon.setImage(newFavicon);
global.mainWindow.setIcon(newFavicon);
});

global.mainWindow.webContents.on('page-title-updated', function(ev, title) {
trayIcon.setToolTip(title);
});
}

export function initApplicationMenu(): void {
Expand Down