"use strict";var g=Object.create;var n=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var b=Object.getPrototypeOf;var S=Object.prototype.hasOwnProperty;var o=(r,e)=>n(r,"name",{value:e,configurable:true});var v=(r,e)=>{for(var t in e)n(r,t,{get:e[t],enumerable:true})};var m=(r,e,t,s)=>{if(e&&typeof e==="object"||typeof e==="function"){for(let i of y(e))if(!S.call(r,i)&&i!==t)n(r,i,{get:()=>e[i],enumerable:!(s=l(e,i))||s.enumerable})}return r};var M=(r,e,t)=>(t=r!=null?g(b(r)):{},m(e||!r||!r.__esModule?n(t,"default",{value:r,enumerable:true}):t,r));var B=r=>m(n({},"__esModule",{value:true}),r);var C={};v(C,{default:()=>d});module.exports=B(C);var u=require("electron");var h=require("mobx");var p=require("dbus-next");var c=require("../environment");var f=M(require("./dbus/Ferdium"));class d{bus=null;trayIcon;ferdium=null;muted=false;unreadDirectMessageCount=0;unreadIndirectMessageCount=0;unreadServices=[];constructor(e){this.trayIcon=e;u.ipcMain.on("initialAppSettings",(t,s)=>{this.updateSettings(s)});u.ipcMain.on("updateAppSettings",(t,s)=>{this.updateSettings(s)});u.ipcMain.on("updateDBusUnread",(t,s,i,a)=>{this.setUnread(s,i,a)})}updateSettings(e){const t=!!e.data.isAppMuted;if(this.muted!==t){this.muted=t;this.ferdium?.emitMutedChanged()}}setUnread(e,t,s){if(this.unreadDirectMessageCount!==e||this.unreadIndirectMessageCount!==t||!h.comparer.structural(this.unreadServices,s)){this.unreadDirectMessageCount=e;this.unreadIndirectMessageCount=t;this.unreadServices=s;this.ferdium?.emitUnreadChanged()}}async start(){if(!c.isLinux||this.bus){return}try{this.bus=(0,p.sessionBus)();await this.bus.requestName("org.ferdium.Ferdium",0)}catch{return}this.ferdium=new f.default(this);this.bus.export("/org/ferdium",this.ferdium);this.bus._addMatch("type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',path='/org/freedesktop/DBus',member='NameOwnerChanged'");const e=JSON.stringify({path:"/org/freedesktop/DBus",interface:"org.freedesktop.DBus",member:"NameOwnerChanged"});this.bus._signals.on(e,t=>{const[s,i,a]=t.body;if(s==="org.kde.StatusNotifierWatcher"&&i!==a&&a!==""){setTimeout(()=>{this.trayIcon.refreshTrayAfterWatcherRestart()},400)}})}stop(){if(!this.bus){return}this.bus.disconnect();this.bus=null;this.ferdium=null}}o(d,"DBus");
