1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-17 08:43:21 +00:00

1. Integrated win-console on windows

2. Updated toaster, to better support linux. And updated flow for windows.
This commit is contained in:
Bryan Roe
2019-05-17 16:10:36 -07:00
parent f4f0a37522
commit bbe2098b7e
2 changed files with 40 additions and 49 deletions

File diff suppressed because one or more lines are too long

View File

@@ -31,22 +31,27 @@ function Toaster()
if (process.platform == 'win32') if (process.platform == 'win32')
{ {
emitter.createEvent('Clicked'); emitter.createEvent('Clicked');
var GM = require('_GenericMarshal');
var kernel32 = GM.CreateNativeProxy('kernel32.dll');
kernel32.CreateMethod('ProcessIdToSessionId');
var psid = GM.CreateVariable(4);
var consoleUid = require('user-sessions').consoleUid();
if (kernel32.ProcessIdToSessionId(process.pid, psid).Val == 0)
{
throw ('Internal Error');
}
var session = require('user-sessions').Current(); if (consoleUid == psid.toBuffer().readUInt32LE())
for (var i in session) { {
console.log(session[i]); // We are running on the physical console
}
try {
console.log('Attempting Toast Mechanism 1');
retVal._child = require('ScriptContainer').Create({ processIsolation: true, sessionId: session.Active[0].SessionId });
}
catch (e) {
console.log(e);
console.log('Attempting Toast Mechanism 2');
retVal._child = require('ScriptContainer').Create({ processIsolation: true }); retVal._child = require('ScriptContainer').Create({ processIsolation: true });
} }
else
{
// We need so spawn the ScriptContainer into the correct session
retVal._child = require('ScriptContainer').Create({ processIsolation: true, sessionId: consoleUid });
}
retVal._child.parent = retVal; retVal._child.parent = retVal;
retVal._child.on('exit', function (code) { this.parent.emit('Dismissed'); delete this.parent._child; }); retVal._child.on('exit', function (code) { this.parent.emit('Dismissed'); delete this.parent._child; });
retVal._child.addModule('win-console', getJSModule('win-console')); retVal._child.addModule('win-console', getJSModule('win-console'));
retVal._child.addModule('win-message-pump', getJSModule('win-message-pump')); retVal._child.addModule('win-message-pump', getJSModule('win-message-pump'));
@@ -75,44 +80,29 @@ function Toaster()
{ {
throw ('Toast not supported on this platform'); throw ('Toast not supported on this platform');
} }
Object.defineProperty(retVal, '_sessions', { if (process.env['DISPLAY'])
value: require('user-sessions').Current(function onCurrentSession(sessions)
{ {
this._cchild = require('child_process').execFile('/usr/bin/whoami', ['whoami'], { type: require('child_process').SpawnTypes.TERM }); // DISPLAY is set, so we good to go
this._cchild.stdout.on('data', function (chunk) retVal._notify = require('child_process').execFile('/usr/bin/notify-send', ['notify-send', retVal.title, retVal.caption]);
{
if (chunk.toString().split('\r\n')[0] == 'root')
{
if (sessions[':0'].State != 'Connected' && sessions[':0'].State != 'Active')
{
// No logged in user owns the display
this.parent.parent.Parent.emit('Dismissed');
return;
}
// We root, so we need to direct to DISPLAY=:0
this.parent.parent._notify = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM });
this.parent.parent._notify.stdin.write('su - ' + sessions[':0'].Username + ' -c "DISPLAY=:0 notify-send \'' + this.parent.parent.Parent.title + '\' \'' + this.parent.parent.Parent.caption + '\'"\n');
this.parent.parent._notify.stdin.write('exit\n');
this.parent.parent._notify.stdout.on('data', function (chunk) { });
} }
else else
{ {
// We ain't root, so that means we can just call send-notify directly // We need to find the DISPLAY to use
this.parent.parent._notify = require('child_process').execFile('/usr/bin/notify-send', ['notify-send', this.parent.parent.Parent.title, this.parent.parent.Parent.caption], { type: require('child_process').SpawnTypes.TERM }); var consoleUid = require('user-sessions').consoleUid();
this.parent.parent._notify.stdout.on('data', function (chunk) { }); var username = require('user-sessions').getUsername(consoleUid);
var display = require('monitor-info').getXInfo(consoleUid).display;
retVal._notify = require('child_process').execFile('/bin/sh', ['sh']);
retVal._notify.stdin.write('su - ' + username + ' -c "DISPLAY=' + display + ' notify-send \'' + retVal.title + '\' \'' + retVal.caption + '\'"\n');
retVal._notify.stdin.write('exit\n');
} }
retVal._notify.stdout.on('data', function (chunk) { });
retVal._notify.waitExit();
// NOTIFY-SEND has a bug where timeouts don't work, so the default is 10 seconds // NOTIFY-SEND has a bug where timeouts don't work, so the default is 10 seconds
this.parent.parent.Parent._timeout = setTimeout(function onFakeDismissed(obj) retVal._timeout = setTimeout(function onFakeDismissed(obj)
{ {
obj.emit('Dismissed'); obj.emit('Dismissed');
}, 10000, this.parent.parent.Parent); }, 10000, retVal);
});
this._cchild.parent = this;
})
});
retVal._sessions.Parent = retVal;
toasters[retVal._hashCode()] = retVal; toasters[retVal._hashCode()] = retVal;
retVal.on('Dismissed', function () { delete toasters[this._hashCode()]; }); retVal.on('Dismissed', function () { delete toasters[this._hashCode()]; });