UNPKG

meshcentral

Version:

Web based remote computer management server

1 lines 3.67 kB
var TrayIconFlags={NIF_MESSAGE:1,NIF_ICON:2,NIF_TIP:4,NIF_STATE:8,NIF_INFO:16,NIF_GUID:32,NIF_REALTIME:64,NIF_SHOWTIP:128,NIM_ADD:0,NIM_MODIFY:1,NIM_DELETE:2,NIM_SETFOCUS:3,NIM_SETVERSION:4},NOTIFYICON_VERSION_4=4,MessageTypes={WM_APP:32768,WM_USER:1024};function WindowsConsole(){"win32"==process.platform&&(this._ObjectID="win-console",this._Marshal=require("_GenericMarshal"),this._kernel32=this._Marshal.CreateNativeProxy("kernel32.dll"),this._user32=this._Marshal.CreateNativeProxy("user32.dll"),this._kernel32.CreateMethod("GetConsoleWindow"),this._kernel32.CreateMethod("GetCurrentThread"),this._user32.CreateMethod("ShowWindow"),this._user32.CreateMethod("LoadImageA"),this._user32.CreateMethod({method:"GetMessageA",threadDispatch:1}),this._shell32=this._Marshal.CreateNativeProxy("Shell32.dll"),this._shell32.CreateMethod("Shell_NotifyIconA"),this._handle=this._kernel32.GetConsoleWindow(),this.minimize=function(){this._user32.ShowWindow(this._handle,6)},this.restore=function(){this._user32.ShowWindow(this._handle,9)},this.hide=function(){this._user32.ShowWindow(this._handle,0)},this.show=function(){this._user32.ShowWindow(this._handle,5)},this._loadicon=function(e){return this._user32.LoadImageA(0,this._Marshal.CreateVariable(e),1,0,0,32848)},this.SetTrayIcon=function(t){var e=this._Marshal.CreateVariable(4==this._Marshal.PointerSize?508:528),s=(e.toBuffer().writeUInt32LE(e._size,0),TrayIconFlags.NIF_TIP|TrayIconFlags.NIF_MESSAGE),i=(t.filter=MessageTypes.WM_APP+1,e.Deref(4==this._Marshal.PointerSize?16:24,4).toBuffer().writeUInt32LE(t.filter),t.noBalloon||(s|=TrayIconFlags.NIF_INFO),t.icon&&(s|=TrayIconFlags.NIF_ICON,i=e.Deref(4==this._Marshal.PointerSize?20:32,this._Marshal.PointerSize),t.icon.pointerBuffer().copy(i.toBuffer())),e.Deref(2*this._Marshal.PointerSize,4).toBuffer().writeUInt32LE(1),e.Deref(4==this._Marshal.PointerSize?12:20,4).toBuffer().writeUInt32LE(s),e.Deref(4==this._Marshal.PointerSize?416:432,4).toBuffer().writeUInt32LE(NOTIFYICON_VERSION_4),e.Deref(4==this._Marshal.PointerSize?24:40,128)),s=e.Deref(4==this._Marshal.PointerSize?160:176,256),r=e.Deref(4==this._Marshal.PointerSize?420:436,64),i=(t.szTip&&Buffer.from(t.szTip).copy(i.toBuffer()),t.szInfo&&Buffer.from(t.szInfo).copy(s.toBuffer()),t.szInfoTitle&&Buffer.from(t.szInfoTitle).copy(r.toBuffer()),require("win-message-pump")),s=(retVal={_ObjectID:"WindowsConsole.TrayIcon",MessagePump:new i(t)},require("events").inherits(retVal));return s.createEvent("ToastClicked"),s.createEvent("IconHover"),s.createEvent("ToastDismissed"),retVal.Options=t,(retVal.MessagePump.TrayIcon=retVal).MessagePump.NotifyData=e,retVal.MessagePump.WindowsConsole=this,retVal.MessagePump.on("exit",function(e){console.log("Pump Exited"),this.TrayIcon&&this.TrayIcon.remove()}),retVal.MessagePump.on("hwnd",function(e){(t.hwnd=e).pointerBuffer().copy(this.NotifyData.Deref(this.WindowsConsole._Marshal.PointerSize,this.WindowsConsole._Marshal.PointerSize).toBuffer()),this.WindowsConsole._shell32.Shell_NotifyIconA(TrayIconFlags.NIM_ADD,this.NotifyData).Val}),retVal.MessagePump.on("message",function(e){e.message==this.TrayIcon.Options.filter&&(1==e.wparam&&1029==e.lparam&&this.TrayIcon.emit("ToastClicked"),1==e.wparam&&512==e.lparam&&this.TrayIcon.emit("IconHover"),!this.TrayIcon.Options.balloonOnly||1!=e.wparam||1028!=e.lparam&&1029!=e.lparam||(this.TrayIcon.emit("ToastDismissed"),this.TrayIcon.remove()))}),retVal.remove=function(){this.MessagePump.WindowsConsole._shell32.Shell_NotifyIconA(TrayIconFlags.NIM_DELETE,this.MessagePump.NotifyData),this.MessagePump.stop(),delete this.MessagePump.TrayIcon,delete this.MessagePump},retVal})}module.exports=new WindowsConsole