"use strict";var p=Object.create;var u=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var T=Object.getPrototypeOf;var b=Object.prototype.hasOwnProperty;var c=(t,i)=>u(t,"name",{value:i,configurable:true});var w=(t,i)=>{for(var s in i)u(t,s,{get:i[s],enumerable:true})};var m=(t,i,s,n)=>{if(i&&typeof i==="object"||typeof i==="function"){for(let a of g(i))if(!b.call(t,a)&&a!==s)u(t,a,{get:()=>i[a],enumerable:!(n=_(i,a))||n.enumerable})}return t};var I=(t,i,s)=>(s=t!=null?p(T(t)):{},m(i||!t||!t.__esModule?u(s,"default",{value:t,enumerable:true}):s,t));var M=t=>m(u({},"__esModule",{value:true}),t);var F={};w(F,{default:()=>h});module.exports=M(F);var y=require("node:path");var e=require("electron");var l=I(require("macos-version"));var r=require("../environment");var o=require("../helpers/i18n-helpers");const A=r.isWindows?"ico":"png";const f="tray";const W="tray-unread";const v="tray-indirect";class h{tray=null;indicator=0;themeChangeSubscriberId=null;trayMenu=null;visible=false;isAppMuted=false;mainWindow=null;currentLocale="en-US";constructor(){e.ipcMain.on("initialAppSettings",(s,n)=>{this._updateTrayMenu(n)});e.ipcMain.on("updateAppSettings",(s,n)=>{this._updateTrayMenu(n)});const[i]=e.BrowserWindow.getAllWindows();this.mainWindow=i;this.mainWindow.on("hide",()=>{this._updateTrayMenu(null)});this.mainWindow.on("restore",()=>{this._updateTrayMenu(null)});this.mainWindow.on("minimize",()=>{this._updateTrayMenu(null)});this.mainWindow.on("show",()=>{this._updateTrayMenu(null)});this.mainWindow.on("focus",()=>{this._updateTrayMenu(null)});this.mainWindow.on("blur",()=>{this._updateTrayMenu(null)})}trayMenuTemplate(i){return[{label:i.mainWindow.isVisible()&&i.mainWindow.isFocused()?(0,o.getTranslatedText)(i.currentLocale,"tray.hideFerdium","Hide Ferdium"):(0,o.getTranslatedText)(i.currentLocale,"tray.showFerdium","Show Ferdium"),click(){i._toggleWindow()}},{label:i.isAppMuted?(0,o.getTranslatedText)(i.currentLocale,"tray.enableNotifications","Enable Notifications && Audio"):(0,o.getTranslatedText)(i.currentLocale,"tray.disableNotifications","Disable Notifications && Audio"),click(){if(!i.mainWindow)return;i.mainWindow.webContents.send("muteApp")}},{label:(0,o.getTranslatedText)(i.currentLocale,"tray.quitFerdium","Quit Ferdium"),click(){e.app.quit()}}]}_updateTrayMenu(i){if(!this.tray){return}if(i&&i.type==="app"){this.isAppMuted=i.data.isAppMuted;if(i.data.locale){this.currentLocale=i.data.locale}}this.trayMenu=e.Menu.buildFromTemplate(this.trayMenuTemplate(this));if(r.isLinux){this.tray.setContextMenu(this.trayMenu)}}show(){this.visible=true;this._show()}_show(){if(this.tray){return}this.tray=new e.Tray(this._getAsset("tray",f));this.tray.setToolTip("Ferdium");this.trayMenu=e.Menu.buildFromTemplate(this.trayMenuTemplate(this));if(r.isLinux){this.tray.setContextMenu(this.trayMenu)}this.tray.on("click",()=>{this._toggleWindow()});if(r.isMac||r.isWindows){this.tray.on("right-click",()=>{if(this.tray&&this.trayMenu){this.tray.popUpContextMenu(this.trayMenu)}})}if(r.isMac){this.themeChangeSubscriberId=e.systemPreferences.subscribeNotification("AppleInterfaceThemeChangedNotification",()=>{this._refreshIcon()})}}_toggleWindow(){const[i]=e.BrowserWindow.getAllWindows();if(i.isMinimized()){i.restore()}else if(i.isVisible()&&i.isFocused()){if(r.isMac&&i.isFullScreen()){i.once("show",()=>i.setFullScreen(true));i.once("leave-full-screen",()=>i.hide());i.setFullScreen(false)}else{i.hide()}}else{i.show();i.focus()}}hide(){this.visible=false;this._hide()}_hide(){if(!this.tray)return;this.tray.destroy();this.tray=null;if(r.isMac&&this.themeChangeSubscriberId){e.systemPreferences.unsubscribeNotification(this.themeChangeSubscriberId);this.themeChangeSubscriberId=null}}recreateIfVisible(){if(this.visible){this._hide();setTimeout(()=>{if(this.visible){this._show()}},100)}}refreshTrayAfterWatcherRestart(){if(!this.visible||!this.tray){return}const i=this._getAsset("tray",this._getAssetFromIndicator(this.indicator));this.tray.setImage(i)}setIndicator(i){this.indicator=i;this._refreshIcon()}_getAssetFromIndicator(i){let s=f;if(i==="\u2022"){s=v}if(i!==0&&i!=="\u2022"){s=W}return s}_refreshIcon(){if(!this.tray){return}this.tray.setImage(this._getAsset("tray",this._getAssetFromIndicator(this.indicator)));if(r.isMac&&!l.default.isGreaterThanOrEqualTo("11")){this.tray.setPressedImage(this._getAsset("tray",`${this._getAssetFromIndicator(this.indicator)}-active`))}}_getAsset(i,s){const{platform:n}=process;let a=n;if(r.isMac&&l.default.isGreaterThanOrEqualTo("11")){a=`${n}-20`}else if(r.isMac&&e.nativeTheme.shouldUseDarkColors){a=`${n}-dark`}const d=e.nativeImage.createFromPath((0,y.join)(__dirname,"..","assets","images",i,a,`${s}.${A}`));if(r.isMac&&l.default.isGreaterThanOrEqualTo("11")){d.setTemplateImage(true)}return d}}c(h,"TrayIcon");
