Is there any APIs to control desktop's power supply(turn on/off, sleep mode)? - flutter

I have a plan to develop Flutter Desktop & mobile App.
My demand is ‘How to control desktop's power supply.’
For instance, when I press the application's button
the desktop turns off/on, or goes to sleep mode.
Is there any APIs on the Flutter Desktop satisfying me? Plz help me.

I think you can achieve this result by using the flutter Process class.
Basically what you want to do is run a command based on the users platform to shutdown or sleep the user's desktop. for an example if you run following command in your windows cmd it will shutdown your pc.
shutdown -s
and in linux you can use following command to shutdown the desktop
sudo shutdown -n now
in theory running the particular commands based the platform from dart process class you can turn off a pc of the user.
for an example to shutdown a windows pc you can use Process.run as following
print("Shutting Down!");
var cleanProcess = await Process.run('shutdown', ["-s"]);
Please refer following documentation for more information
Flutter Process Class
Linux shutdown commands
Windows shutdown commands

Related

Why does VS Code remote WSL launch mstsc.exe (Remote Desktop Connection)?

I've noticed whenever I launch a VS Code WSL session I get an mstsc.exe (Remote Desktop Client) process running. I don't think this is a problem in itself however mstsc is causing some flickering and poor overall system performance even though CPU and memory usage isn't excessive.
How is mstsc.exe related to VS Code Remote WSL? Is it needed if I'm not running any graphical desktop applications in WSL? Can th remote session run without mstsc?
I had never noticed this prior to upgrading to Windows 11 in case that's significant.
I use this app https://superuser.com/a/1042066/3489 to identify mstsc.exe as the cause of desktop / input focus flickering.
Event Viewer > Windows Logs > Security > Microsoft Windows security auditing confirmed it was mstsc.exe being launched by Creator Process Name: C:\Windows\System32\lxss\wslhost.exe
And finally wsl --shutdown made it stop.
If don't want to disable WSLg you could try the solution of this similar problem: https://github.com/microsoft/wslg/issues/676.
For me, updating wsl from aka.ms/wslstorepage seems to have solved the flickering problem.

Running the firebase emulators when the functions directory is in a different project/location

I am running all the firebase emulators locally on a windows 10 machine.
However I am running my functions emulator separately as the functions dir is in a different project/location.
It appears the triggers are not being emulated and I get the warning below. Everything apart from the trigger/background functions appears to work fine.
Any solutions?
i emulators: Starting emulators: functions
! hub: emulator hub unable to start on port 4400, starting on 4401 instead.
! emulators: It seems that you are running multiple instances of the emulator suite for project myproject-dev. This may result in unexpected behavior.
! functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, firestore, database, hosting, pubsub
! Your requested "node" version "10" doesn't match your global version "12"
! logging: Logging Emulator unable to start on port 4500, starting on 4501 instead.
! ui: Emulator UI unable to start on port 4000, starting on 4003 instead.
i ui: Emulator UI logging to ui-debug.log
i functions: Watching "R:\myproject\myprojectCloud\functions" for Cloud Functions...
! functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
i functions[memberUpdate]: function ignored because the firestore emulator does not exist or is not running.
Update:
My folder structure.
R:/customer/customer-cloud-project/functions
R:/cusomer/customer-web-app/
I can run all the emulators in location 2 fine except the functions emulator as there is no functions directory.
So I run the following in location 1 in the functions folder:
firebase emulators:start --only functions
This works fine as it runs 2 instances of the emulator. However the trigger/background functions do not run as it can't find the firestore emulator running on a different port.
The solution to this is to use symbolic links.
This is basically a shortcut to another directory located in the functions project.
If anyone else want to do this the command on Windows is:
mklink /D "R:\firestore-project\functions" "R:\cloud-functions-proj\functions"
You will need to run the command prompt as admin.
See my issue here for more details:
https://github.com/firebase/firebase-tools/issues/3092#issuecomment-771159457
Note:
You can specify an absolute or relative path when creating the symbolic link.
Relative is the best option otherwise it is unlikely it will work in someone else's environment. Run this in the dir where you want to create the link:
mklink /D "models" "..\..\..\myapp\src\app\models"

Error "System UI isn't responding" while running AOSP build on emulator

I am trying to run AOSP(oreo 8.1) build on emulator.
I used following commands to build AOSP.
source build/envsetup.sh
lunch aosp_arm-eng
make -j4
my build was successful. Now i'm trying to run on emulator using following command.
emulator
emulator is started with following warning message.
Could not automatically detect an ADB binary. Some emulator functionality will not work until a custom path to ADB is added in the extended settings page.
After successful boot "System UI isn't responding" message is displaying on the emulator, also emulator is running real slow.
Any help in resolving this issue is greatly appreciated.
emulator screenshot: system ui isn't responding
emulator: WARNING: system partition size adjusted to match image file (2050 MB > 200 MB)
emulator: WARNING: encryption is off
main-loop: WARNING: I/O thread spun for 1000 iterations
It often occurs - especially on slow machines running CPU-consuming emulations, that an emulator would initially load into a state where a System UI isn't responding alert shows. It does not necessarily mean the device isn't working; Often enough, the alert can be dismissed and the device will be completely functional from that point on.
I'm not sure what the exact issue to solve here is. Nevertheless, assuming you're running on CI and - besides the emulator's sluggishness, wish to overcome the System UI isn't responding alert appearing upon boot completion (as suggested by the title) -- may I suggest this bash script (gist):
#!/bin/bash
echo ""
echo "[Waiting for launcher to start]"
LAUNCHER_READY=
while [[ -z ${LAUNCHER_READY} ]]; do
UI_FOCUS=`adb shell dumpsys window windows 2>/dev/null | grep -i mCurrentFocus`
echo "(DEBUG) Current focus: ${UI_FOCUS}"
case $UI_FOCUS in
*"Launcher"*)
LAUNCHER_READY=true
;;
"")
echo "Waiting for window service..."
sleep 3
;;
*"Not Responding"*)
echo "Detected an ANR! Dismissing..."
adb shell input keyevent KEYCODE_DPAD_DOWN
adb shell input keyevent KEYCODE_DPAD_DOWN
adb shell input keyevent KEYCODE_ENTER
;;
*)
echo "Waiting for launcher..."
sleep 3
;;
esac
done
echo "Launcher is ready :-)"
The script awaits for the launcher to become ready and in-focus, and automatically dismisses system responsiveness alerts, coming its way.
It in no way addresses the emulator's sluggishness, however.
See this answer from another question to fix the ADB error. However, this will likely not fix the responsiveness of your emulator.
The emulator tends to function extremely slowly if you are compiling aosp for a different architecture than your host machine. If you are building on an x86 machine an x86 build will result in a significantly faster emulator that won't eat up all of your machine's resources.
May be this answer could be helpful for someone who have made a mistake like me and could save his time.
I faced this issue on my physical device as i used an app icon of very large size (2100x2100). I resolved it by using an app icon of low size(512x512).

how to run swift server single process

I'm trying to run a swift based web server using Kitura on Ubuntu.
This is following command to start hello word server.
.build/debug/helloworld
I can launch standalone process using .build/debug/helloworld &
but launching with that creates multiple process if execute again.
Or I've to kill old process then start new If I want to run only single process.
I've followed following tutorial to get server up running. But don't want to use Bluemix to deploy application. Instead I want to launch it on AWS ubuntu.
http://www.kitura.io/en/starter/gettingstarted.html
I assume there must be more easy and proper way to do this.
As you can see I'm almost newbie for servers.
You have to kill the Kitura process in order to stop a Kitura Server app - there is no other way to stop it.
If you just want to test your server you can run it inside a screen session. Screen is an essential utility for managing remote servers via ssh.
If you want to run it properly as a service/daemon you should look into systemd.

Connect to console app running as a system task on Windows server

I run several game servers on a single windows-server-2012-r2. Many of the game servers run as console-application. I have created scheduled-tasks to run each on windows startup even if I'm not logged on. I would like to be able to attach to the consoles of those apps when logged on to the server, similar to what can be done in linux. Perhaps I'm going about this in the wrong way. Is there a way to attach to console apps running as tasks? Is there a software tool that accommodates this sort of thing?
Update:
Been searching high and low for a solution but haven't found anything yet. Have decided to write a wrapper for console app that will redirect Stdin, Stdout and Stderr of a process to a Telnet connection. Will use nssm to run the wrapper as a service.
I produced a solution: https://github.com/ccourson/Banjo
Banjo will launch a specified console application and route its streams to and from a telnet connection.
Pull requests welcome.