summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2023-07-09 16:32:42 -0400
committerKjetil Orbekk <kj@orbekk.com>2023-07-09 16:32:42 -0400
commitbd5bc63483a815a60056a6dff481cc513ec62ef9 (patch)
tree5e1daddef5c426167e114ad6c4681773b76fe9f4
parent14548ad9946d60a0d28f3ac604b217a467c0be05 (diff)
spawn X server for geckodriverHEADmaster
-rw-r--r--dashboard.sh24
-rw-r--r--flake.nix17
-rw-r--r--src/main.rs23
3 files changed, 48 insertions, 16 deletions
diff --git a/dashboard.sh b/dashboard.sh
new file mode 100644
index 0000000..0d37ef0
--- /dev/null
+++ b/dashboard.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env sh
+DEBUG=${DEBUG:-false}
+[ "$DEBUG" = true ] && set -x
+
+DIR="$(dirname "$0")"
+DASH_PNG="$DIR/dash.png"
+
+/etc/init.d/framework stop
+initctl stop webreader >/dev/null 2>&1
+echo powersave >/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
+lipc-set-prop com.lab126.powerd preventScreenSaver 1
+
+i=0
+while true; do
+ curl -H "Host: insecure.orbekk.com" http://172.20.20.2/tmp/dashboard.png -o $DASH_PNG
+ if [ $i -eq 10 ]; then
+ i=0
+ /usr/sbin/eips -f -g "$DASH_PNG"
+ else
+ i=$((i + 1))
+ /usr/sbin/eips -g "$DASH_PNG"
+ fi
+ sleep 30
+done
diff --git a/flake.nix b/flake.nix
index 4e5d1b6..b05fb5b 100644
--- a/flake.nix
+++ b/flake.nix
@@ -40,11 +40,13 @@
commonArgs = {
inherit src;
- buildInputs = [
- # Add additional build inputs here
- ] ++ lib.optionals pkgs.stdenv.isDarwin [
- # Additional darwin specific inputs can be set here
- pkgs.libiconv
+ buildInputs = with pkgs; [
+ xorg.xorgserver
+ firefox
+ geckodriver
+ pkg-config
+ openssl
+ imagemagick
];
# Additional environment variables can be set directly
@@ -141,11 +143,6 @@
"rustfmt"
])
rust-analyzer-nightly
- firefox
- geckodriver
- pkg-config
- openssl
- imagemagick
];
};
});
diff --git a/src/main.rs b/src/main.rs
index b3635ee..cf5537d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,9 +11,17 @@ static PROFILE_ROOT: &str = "/tmp/geckodriver-dashboard";
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
+ /// Input HTML file.
+ #[arg(short, long)]
+ input_path: String,
+
/// Output path for png image.
#[arg(short, long)]
- path: String,
+ output_path: String,
+
+ /// CSS locator to generate screenshot for.
+ #[arg(default_value_t = String::from("#app"))]
+ element_locator: String,
}
// let's set up the sequence of steps we want the browser to take
@@ -21,11 +29,14 @@ struct Args {
async fn main() -> Result<(), Box<dyn Error>> {
pretty_env_logger::init();
let args = Args::parse();
- let display = env::var("DISPLAY")?;
+ let display = ":5"; // env::var("DISPLAY")?;
+
+ let _xvfb = Command::new("Xvfb")
+ .arg(display).spawn()?;
info!("Current directory: {}", env::current_dir()?.display());
fs::create_dir(PROFILE_ROOT).ok();
- let mut geckodriver = Command::new("geckodriver")
+ let _geckodriver = Command::new("geckodriver")
.env("MOZ_REMOTE_SETTINGS_DEVTOOLS", "1")
.env("DISPLAY", display)
.arg("--profile-root").arg("/tmp/geckodriver-dashboard").spawn()?;
@@ -33,14 +44,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
let c = ClientBuilder::native().connect("http://localhost:4444").await.expect("failed to connect to WebDriver");
loop {
- let path = fs::canonicalize("index.html")?;
+ let path = fs::canonicalize(&args.input_path)?;
info!("Opening {}", path.display());
c.goto(&format!("file://{}", path.display())).await?;
- let e = c.find(Locator::Css("#app")).await?;
+ let e = c.find(Locator::Css(&args.element_locator)).await?;
let img = e.screenshot().await?;
- let output_path = Path::new(&args.path);
+ let output_path = Path::new(&args.output_path);
let tmp_path = output_path.with_extension("png.tmp");
fs::write(&tmp_path, img)?;