mirror of
				https://github.com/zulip/zulip-desktop.git
				synced 2025-11-03 21:43:18 +00:00 
			
		
		
		
	node-mac-notifier no longer builds on macOS with Electron 11 (error: no template named 'remove_cv_t' in namespace 'std'). It was previously implicated in crashes on macOS (#1016). And we no longer have any macOS developers that seem to be maintaining this feature (e.g. #1022 is stalled). Signed-off-by: Anders Kaseorg <anders@zulip.com>
		
			
				
	
	
		
			64 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import {remote} from 'electron';
 | 
						|
 | 
						|
import DefaultNotification from './default-notification';
 | 
						|
import {appId} from './helpers';
 | 
						|
 | 
						|
const {app} = remote;
 | 
						|
 | 
						|
// From https://github.com/felixrieseberg/electron-windows-notifications#appusermodelid
 | 
						|
// On windows 8 we have to explicitly set the appUserModelId otherwise notification won't work.
 | 
						|
app.setAppUserModelId(appId);
 | 
						|
 | 
						|
export interface NotificationData {
 | 
						|
	close: () => void;
 | 
						|
	title: string;
 | 
						|
	dir: NotificationDirection;
 | 
						|
	lang: string;
 | 
						|
	body: string;
 | 
						|
	tag: string;
 | 
						|
	image: string;
 | 
						|
	icon: string;
 | 
						|
	badge: string;
 | 
						|
	vibrate: readonly number[];
 | 
						|
	timestamp: number;
 | 
						|
	renotify: boolean;
 | 
						|
	silent: boolean;
 | 
						|
	requireInteraction: boolean;
 | 
						|
	data: unknown;
 | 
						|
	actions: readonly NotificationAction[];
 | 
						|
}
 | 
						|
 | 
						|
export function newNotification(
 | 
						|
	title: string,
 | 
						|
	options: NotificationOptions | undefined,
 | 
						|
	dispatch: (type: string, eventInit: EventInit) => boolean
 | 
						|
): NotificationData {
 | 
						|
	const notification = new DefaultNotification(title, options);
 | 
						|
	for (const type of ['click', 'close', 'error', 'show']) {
 | 
						|
		notification.addEventListener(type, (ev: Event) => {
 | 
						|
			if (!dispatch(type, ev)) {
 | 
						|
				ev.preventDefault();
 | 
						|
			}
 | 
						|
		});
 | 
						|
	}
 | 
						|
 | 
						|
	return {
 | 
						|
		close: () => notification.close(),
 | 
						|
		title: notification.title,
 | 
						|
		dir: notification.dir,
 | 
						|
		lang: notification.lang,
 | 
						|
		body: notification.body,
 | 
						|
		tag: notification.tag,
 | 
						|
		image: notification.image,
 | 
						|
		icon: notification.icon,
 | 
						|
		badge: notification.badge,
 | 
						|
		vibrate: notification.vibrate,
 | 
						|
		timestamp: notification.timestamp,
 | 
						|
		renotify: notification.renotify,
 | 
						|
		silent: notification.silent,
 | 
						|
		requireInteraction: notification.requireInteraction,
 | 
						|
		data: notification.data,
 | 
						|
		actions: notification.actions
 | 
						|
	};
 | 
						|
}
 |