INFO: I'm a Emacs user used to develop mobile apps with react-native.
Description
Recently, I'm trying to develop a flutter app, stuck with the hot-reload part, I hope that flutter can reload automatically when I make changes to lib/*dart.
What I am thinking about is watching the lib/*dart's modification, as it happen, passing a r to the flutter process automatically.
How can I reach the flutter run process?
Solution
Emacs Solution
After reading Hot reload on save over and over again, I updated my Emacs' configuration file:
(require 'dart-mode)
(defun auto-reload ()
(shell-command "kill -s SIGUSR1 $(cat /tmp/flutter.pid) && echo 'reload flutter...'"))
(add-hook 'dart-mode-hook
(lambda ()
(add-hook 'after-save-hook 'auto-reload nil 'make-it-local)))
It's quite easy, that I can't believe it...kill the flutter run process, and it will reload automatically, after sending signal kill -SIGUSR1 to flutter run process through our shell-script.
Thanks #pskink, I had took my brain and tried again, then, the problem has been solved.
I checked the description about linux signal again, the kill command described as:
Sends a signal to a specified process, to all members of a specified process group, or to all processes on the system.
Not just rudely killing processes...and here is the description of kill in command-line:
kill [-s sigspec | -n signum | -sigspec] pid | jobspec
...or
kill -l [sigspec]
However, the flag --pid-file of flutter is described like this:
Specify a file to write the process id to. You can send SIGUSR1 to trigger a hot reload and SIGUSR2 to trigger a hot restart.
We kill -SIGUSR1 $(cat /tmp/flutter.pid), as we send signal SIGURS1 to the flutter process, that's what happened.
I'm still wondering, if we can just send a r to the 'screen' of the flutter run process?
https://pub.dartlang.org/packages/angel_hot and https://pub.dartlang.org/packages/jaguar_hotreload are packages for hot-reload support for server-side development - to hot-reload on file changes.
I'd expect this to work for Flutter as well.
You can also investigate the source and create a custom implementation.
The functionality is provided by the Dart observatory, a service built into the VM that you can connect to and that can be controlled over commands.
See also https://github.com/dart-lang/sdk/blob/master/runtime/vm/service/service.md
Related
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
I'm using VS Code to write and debug a C++ program binding to libfuse.
Unfortunately, if you kill a libfuse process with SIGKILL, you then have to use sudo umount -f <mountpoint> before you can start the program again. It's a minor nuisance if I have to do this every time I want to stop or restart debugging, especially as I shouldn't have to authenticate to do such a regular task (the sudo is somehow necessary despite the mount occurring as my user).
While I think this is mainly FUSE's fault (it should gracefully recover from a process being ungracefully killed and unmount automatically instead of leaving the directory saying Transport endpoint is not connected), I also think there should be a way to customise VS Code (or any IDE) to run some clean-up when you want to stop debugging.
I've found that entering -exec signal SIGTERM in the Debug Console will gracefully unmount the directory correctly, stop the process and tell VS Code it's no longer debugging (status bar changes back from orange to blue). But I can't seem to find a way to automate this. I've tried using a .gdbinit file, with some inspiration from this question:
handle SIGTERM nostop
# This doesn't work as hook-quit isn't run when quitting via MI mode, which VS Code uses...
define hook-quit
signal SIGTERM
end
But as noted in the linked question, GDB ignores quit hooks when in MI mode, and VS Code uses MI mode.
The ideal solution for me would be if I could put something in a .vscode configuration file telling it to send -exec signal SIGTERM when I click the stop or restart buttons (and then wait for whatever notification it's getting that debugging has stopped, before restarting if applicable) but I imagine there probably isn't an option for that.
Even if the buttons can't be customised, I'd be happy with the ability to have a keybinding that would just send -exec signal SIGTERM to the Debug Console without me having to open said console and enter the command, though the Command Palette doesn't show anything useful here (nothing that looks like it will send a specified Debug Console command), so I don't expect there's a bindable command for that either.
Does anyone have any suggestions? Or would these belong as feature requests over on the VS Code github? Any way to get GDB to respect its quit hook in MI mode, or to get FUSE to gracefully handle its process being killed would be appreciated too.
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).
I have a dev server which I often push code changes to over Git. After each push, I need to manually log into the server and restart the supervisor processes.
Is there a way to have Supervisor monitor a filesystem directory for changes and reload the process(es) on changes?
You should be able to use an Event Listener which monitors the filesystem (with perhaps watchdog) and emits a restart using the XML-RPC API. Check out the memmon listener from the superlance package for inspiration. It wouldn't need to be that complicated. And since the watchdog would call your restart routine you don't need to read the events using childutils.listener.wait.
Alternatively, git hooks might do the trick if the permissions are correct for the supervisord API to be accessed (socket permissions, HTTP passwords). A simpler but less-secure approach.
A simpler and even less-secure approach would be to allow you to issue a supervisorctl restart. The running user has to match your push user (or git, or www, depending on how you have it setup). Lot's of ways to have it go wrong security-wise. But for development, might do fine.
Related:
Supervisord: is there any way to touch-reload a child?
I also didn't find any solution so I tried to make my own.
Here it is.
You can install the package by this command:
pip install git+https://github.com/stavinsky/supervisord-touch-reload.git
(I will add it to PyPI after adding some tests. )
An example of setting up supervisor located in examples folder in github. Documentation will be very soon, I believe.
Basically all you need to start use this module is add event listener with command like:
python -m touch_reload --socket unix:///tmp/supervisor.sock --file <path/to file file> --program <program name>
where file is a file that will be monitored with absolute or relative to directory path, socket is the socket from supervisorctl section and program is program name from [program:<name>] section definition.
Also available --username and --password, that you can use if you have custom supervisor configuration.
While not a solution which uses supervisor, I typically solve this problem within the supervised app. For instance, add the --reload flag to gunicorn and it will reload whenever your app changes.
I had the same problem and created Superfsmon which can do what you want: https://github.com/timakro/superfsmon
pip install superfsmon
Here's a simple example from the README:
To restart your celery workers on changes in the /app/devops
directory your supervisord.conf could look like this.
[program:celery]
command=celery -A devops.celery worker --loglevel=INFO --concurrency=10
[program:superfsmon]
command=superfsmon /app/devops celery
Here is one liner solution with inotify tools:
apt-get install -y inotify-tools
while true; do inotifywait -r src/ && service supervisor restart; done
I am trying to find a hook in Emacs, which should fire right before emacs server graceful shutdown.
I tried kill-emacs-query-functions, kill-emacs-hook, server-done-hook with elisp like :
(add-hook 'server-done-hook
'(lambda ()
(savehist-save)
)
)
... but none of them is called when OS shuts down, so history is not saved.
Maybe someone could give a hint?
P.S. I am on Gentoo Linux, emacs-vcs-23.2.9999 package, terminal only. For testing desired behaviour Emacs is stopped using start-stop-daemon utility.
Since Emacs 24.1, Emacs runs kill-emacs which runs the functions in kill-emacs-hook. So the question, and the rest of this answer, are only relevant to older versions.
The right place to run something before Emacs shuts down is either kill-emacs-query-function if you want to be able to cancel the shutdown or kill-emacs-hook if you don't. The problem you're facing is that your OS does not notify Emacs to shut down gracefully in a way that Emacs understands, or to look at it the other way, Emacs does not understand your OS's request to suht down gracefully.
A graceful way of shutting down Emacs 23 from the outside is to run emacsclient -n -e '(kill-emacs)'. That's obviously not a generic way of telling a program to shut down gracefully.
The normal way to shut down a process gracefully on unix is to send it a SIGHUP or SIGTERM signal. Unfortunately, Emacs treats almost all signals as fatal, and only runs an emergency auto save and no lisp code when it receives them. This is not configurable from lisp. A different behavior has been requested, but turned down.
A partial workaround (found here) is to run session saving hooks in delete-frame-functions. This hook is likely to be run before the system shutdown sequence, either when you close your last frame or when the X server dies (taking your terminals with them if you run Emacs in a terminal). Make sure you don't run the hook that kills the server in delete-frame-functions.
By the way, if you were going to use this exact hook, note that your code is a complicated way of writing (add-hook 'server-done-hook 'savehist-save), and that's not useful since there's already savehist-autosave in kill-emacs-hook.