Can I embed an external component in a Windows 7 gadget? - components

Some features I needed is not available in the Javascript API. Is it possible to use an external component (C++ or whatever) in a gadget? In particular, I'd like to get a list of running processes.

You can access WMI objects (or pretty much any COM object) from a gadget. For example the following WMI JScript will dump all processes on the system to the gadget window (put it in the HTML).
try {
var wmi = GetObject("winmgmts:\\\\.\\root\\CIMV2");
var items = wmi.ExecQuery("SELECT * FROM Win32_Process");
var i = 0;
while(i < items.Count)
{
var item = items.ItemIndex(i);
document.writeln(item.Name);
i++;
}
} catch(e) {
document.write(e.message);
}

Related

Requesting Android permissions in Qt 6

I am trying to convert a Qt 5 app to Qt 6.
In Qt 5 we can request Android permissions as follows:
QStringList permissions;
//...
QtAndroid::PermissionResultMap resultHash = QtAndroid::requestPermissionsSync(permissions);
for (const auto &perm : permissions)
{
if(resultHash[perm] == QtAndroid::PermissionResult::Denied)
{
qDebug() << "Permission denied:" << perm;
return false;
}
}
What is the equivalent in Qt 6? Or is the only way to manually implement this using JNI?
Regards
Here is the new Qt6 permission API (which is still under development, however can be used): QtAndroidPrivate Namespace
Example:
#include <QtCore/private/qandroidextras_p.h>
bool checkPermission()
{
auto r = QtAndroidPrivate::checkPermission(QtAndroidPrivate::Storage).result();
if (r == QtAndroidPrivate::Denied)
{
r = QtAndroidPrivate::requestPermission(QtAndroidPrivate::Storage).result();
if (r == QtAndroidPrivate::Denied)
return false;
}
return true;
}
There is no permission handling API in Qt6 yet. However, it is under making. You can follow the situation from QTBUG-90498. It looks like it is scheduled for Qt6.4 release which I assume will be due some time in the fall 2022. You can find a code review link from the bug report which might help you in writing your own implementation.
I would recommend you to take a look into QNativeInterface::QAndroidApplication::runOnAndroidMainThread which you can use for asynchronous calling on the Android UI thread.

How could I change the audio output device of node module "say"

I'm making a program that will output text to speech, the user will need to be able to change the output device (for example to virtual audio cable). At the moment I'm using https://www.npmjs.com/package/say to produce the speech
e.g.
const say = require("say");
say.speak("Hello World");
but I've no clue on how I could go about choosing the audio output.
What I've found so far has been pretty useless, I'm guessing largely because I don't know the proper terminology to search for answers, regardless this is it:
I first found out about navigator.MediaDevices, then I found how I could make an audio element and change the audio device of that element via setSinkId, then I realized these things are probably(?) irrelevant since the say module seems to play sounds using powershell commands. I've even gone as far as trying to change powershell's output device in app volume device preferences(img), but that seems to do nothing.
I'm pretty much stumped right now, so I'd appreciate any help please. I'm not set on using Say as a module, it just seemed easy to use at first.
Edit:
A workaround I've settled with is making my own TTS class and using SpVoice.
I have something similar to this:
const childProcess = require('child_process');
class TTS {
constructor(channel, speed) {
this.speed = speed;
this.channel = channel;
this.baseCommand = "$speak = New-Object -ComObject SAPI.SPVoice;"
}
speak(text){
var command = this.baseCommand +
`$speak.AudioOutput = foreach ($o in $speak.GetAudioOutputs()) {if ($o.getDescription() -eq '${this.channel}') {$o; break;}}; `
+ "$speak.Speak([Console]::In.ReadToEnd());"
this.child = childProcess.spawn('powershell', [command], {shell: true})
this.child.stdin.setEncoding('ascii')
this.child.stdin.end(text);
this.child.addListener('exit', (code, signal) => {
if (code === null || signal !== null) {
console.log(new Error(`error [code: ${code}] [signal: ${signal}]`))
}
this.child = null
})
}
}
Then I can pass in an audio channel like
tts = new TTS("CABLE Input (VB-Audio Virtual Cable)", 0);
tts.speak("Hello there");
and it will output TTS in my desired channel
Some of the browsers support the built in speechSynthesis API.
Save the following code in 'test.html' file and open the file in chrome web browser for testing the speech api.
<script>
//---------------- SpeechAPI Start ------------------------
function speak(message) {
try {
var utterance= new SpeechSynthesisUtterance("");
utterance.lang='en-GB';
utterance.text=message;
window.speechSynthesis.speak(utterance);
}catch(e){
console.log('Exception in speak : ' + e)
}
}
//---------------- SpeechAPI End ------------------------
</script>
<button onclick="speak('Hello, how are you doing?');">Press to speak</button>
Is this what you are looking for ?

Web browser with no title / windows bars

I've been looking into this for awhile now as I have created a client I would love to be able to run in a separate window (In a similar design to the Blizzard launcher or the old Ijji reactor). I was wondering if this was possible. Last week I created a web browser within Visual Basic but I was not happy with the final result at the bars where still stationed around the window. Any helpful tips or advice would be appreciated!
You didn't specify language, so you get it in c#. This might work. Starts chrome in app mode. here is the argument list
http://peter.sh/experiments/chromium-command-line-switches/
url = "--app=http://google.com";
Process[] pname = Process.GetProcessesByName("chrome");
if (pname.Length == 0)
{
chrome = false;
}
else // if chrome is running
{
if (!chrome)
{
Process process = new Process();
process.StartInfo.FileName = "chrome";
process.StartInfo.Arguments = url;
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.Start();
//Process.Start("chrome", url);
}
chrome = true;
}

When to use drmModeFreeResources after a drmModeGetResources?

If I'm working with drm on linux and trying to get the number of displays/connectors on a gpu, when do I need to call drmModeFreeResources/Connector?
drmModeResPtr drmResources = drmModeGetResources(drmFd);
for (int i = 0; i < drmResources->count_connectors; i++) {
drmModeConnectorPtr connector;
connector = drmModeGetConnector(drmFd, drmResources->connectors[i]);
if (connector && connector->connection == DRM_MODE_CONNECTED) {
do_something();
}
drmModeFreeConnector(connector); // Do I need to do this?
}
drmModeFreeResources(drmResources); // Do I need to do this?
Do I need to free every time I get resources/connector? Or do I only need to do it after I'm done with the resources and want to destroy them, such as when the connector or display is no longer connected?
Thanks

Identify the w3wp System.Diagnostics.Process for a given application pool

I got few web sites running on my server.
I have a "diagnostic" page in an application that shows the amount of memory for the current process (very useful).
Now this app is 'linked' to another app, and I want my diagnostic page to be able to display the amot of memory for another w3wp process.
To get the amount of memory, I use a simple code :
var process = Process.GetProcessesByName("w3wp");
string memory = this.ToMemoryString(process.WorkingSet64);
How can I identify my second w3wp process, knowing its application pool ?
I found a corresponding thread, but no appropriate answer :
Reliable way to see process-specific perf statistics on an IIS6 app pool
Thanks
You could use WMI to identify to which application pool a given w3wp.exe process belongs:
var scope = new ManagementScope(#"\\YOURSERVER\root\cimv2");
var query = new SelectQuery("SELECT * FROM Win32_Process where Name = 'w3wp.exe'");
using (var searcher = new ManagementObjectSearcher(scope, query))
{
foreach (ManagementObject process in searcher.Get())
{
var commandLine = process["CommandLine"].ToString();
var pid = process["ProcessId"].ToString();
// This will print the command line which will look something like that:
// c:\windows\system32\inetsrv\w3wp.exe -a \\.\pipe\iisipm49f1522c-f73a-4375-9236-0d63fb4ecfce -t 20 -ap "NAME_OF_THE_APP_POOL"
Console.WriteLine("{0} - {1}", pid, commandLine);
}
}
You can also get the PID using the IIS ServerManager component; way, if you need to access it in code, without redirecting and parsing console output;
public static int GetIISProcessID(string appPoolName)
{
Microsoft.Web.Administration.ServerManager serverManager = new
Microsoft.Web.Administration.ServerManager();
foreach (WorkerProcess workerProcess in serverManager.WorkerProcesses)
{
if (workerProcess.AppPoolName.Equals(appPoolName))
return workerProcess.ProcessId;
}
return 0;
}

Resources