From b11e239779dacb790cf03d595f8f36cce6956bd9 Mon Sep 17 00:00:00 2001 From: Petros Amoiridis Date: Thu, 20 Apr 2023 18:35:35 +0300 Subject: [PATCH 1/6] Make the script more reliable --- script/start-local-collaboration | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/script/start-local-collaboration b/script/start-local-collaboration index 8906593509..4748ca0474 100755 --- a/script/start-local-collaboration +++ b/script/start-local-collaboration @@ -26,7 +26,7 @@ fi # Make each Zed instance take up half of the screen. resolution_line=$(system_profiler SPDisplaysDataType | grep Resolution | head -n1) -screen_size=($(echo $resolution_line | egrep -o '[0-9]+')) +screen_size=($(echo $resolution_line | egrep -o '\s*(\d+)\s*x\s*(\d+).*)' | egrep -o '[0-9]+')) scale_factor=1 if [[ $resolution_line =~ Retina ]]; then scale_factor=2; fi width=$(expr ${screen_size[0]} / 2 / $scale_factor) @@ -36,6 +36,17 @@ y=0 position_1=0,${y} position_2=${width},${y} +# Uncomment the following for debugging purposes. +# echo "Resolution line: $resolution_line" +# echo "Screen size: $screen_size" +# echo "Screen size 0: ${screen_size[0]}" +# echo "Screen size 1: ${screen_size[1]}" +# echo "Scale factor: $scale_factor" +# echo "Width: $width" +# echo "Height: $height" +# echo "Position 1: $position_1" +# echo "Position 2: $position_2" + # Authenticate using the collab server's admin secret. export ZED_STATELESS=1 export ZED_ADMIN_API_TOKEN=secret From 460ea8e16c63ef48b3551c524f8d35e6441953d3 Mon Sep 17 00:00:00 2001 From: Petros Amoiridis Date: Thu, 20 Apr 2023 18:47:41 +0300 Subject: [PATCH 2/6] Increase reliability and support multiple monitors --- script/start-local-collaboration | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/script/start-local-collaboration b/script/start-local-collaboration index 4748ca0474..0373662715 100755 --- a/script/start-local-collaboration +++ b/script/start-local-collaboration @@ -25,33 +25,26 @@ if [[ $username_1 == $username_2 ]]; then fi # Make each Zed instance take up half of the screen. -resolution_line=$(system_profiler SPDisplaysDataType | grep Resolution | head -n1) -screen_size=($(echo $resolution_line | egrep -o '\s*(\d+)\s*x\s*(\d+).*)' | egrep -o '[0-9]+')) -scale_factor=1 -if [[ $resolution_line =~ Retina ]]; then scale_factor=2; fi -width=$(expr ${screen_size[0]} / 2 / $scale_factor) -height=${screen_size[1] / $scale_factor} + +output=$(system_profiler SPDisplaysDataType -json) +resolution=$(echo "$output" | jq -r '.SPDisplaysDataType[0].spdisplays_ndrvs[] | select(.spdisplays_online == "spdisplays_yes") | ._spdisplays_resolution') +width=$(echo "$resolution" | jq -Rr 'split(" x ")[0]') +half_width=$(($width / 2)) +height=$(echo "$resolution" | jq -Rr 'split(" x ")[1]') y=0 -position_1=0,${y} -position_2=${width},${y} +echo "Width: $width" +echo "Half-width: $half_width" +echo "Height: $height" -# Uncomment the following for debugging purposes. -# echo "Resolution line: $resolution_line" -# echo "Screen size: $screen_size" -# echo "Screen size 0: ${screen_size[0]}" -# echo "Screen size 1: ${screen_size[1]}" -# echo "Scale factor: $scale_factor" -# echo "Width: $width" -# echo "Height: $height" -# echo "Position 1: $position_1" -# echo "Position 2: $position_2" +position_1=0,${y} +position_2=${half_width},${y} # Authenticate using the collab server's admin secret. export ZED_STATELESS=1 export ZED_ADMIN_API_TOKEN=secret export ZED_SERVER_URL=http://localhost:8080 -export ZED_WINDOW_SIZE=${width},${height} +export ZED_WINDOW_SIZE=${half_width},${height} cargo build sleep 0.5 From dcc804783cbb6e214e6e639fdf6de462ae774253 Mon Sep 17 00:00:00 2001 From: Petros Amoiridis Date: Thu, 20 Apr 2023 18:50:06 +0300 Subject: [PATCH 3/6] Install jq if it's missing --- script/start-local-collaboration | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/script/start-local-collaboration b/script/start-local-collaboration index 0373662715..7a94982a5a 100755 --- a/script/start-local-collaboration +++ b/script/start-local-collaboration @@ -17,6 +17,12 @@ MESSAGE exit 1 fi +# Install jq if it's not installed +if ! command -v jq &> /dev/null; then + echo "Installing jq..." + brew install jq +fi + # Start one Zed instance as the current user and a second instance with a different user. username_1=$(curl -sH "Authorization: bearer $GITHUB_TOKEN" https://api.github.com/user | jq -r .login) username_2=nathansobo @@ -25,7 +31,6 @@ if [[ $username_1 == $username_2 ]]; then fi # Make each Zed instance take up half of the screen. - output=$(system_profiler SPDisplaysDataType -json) resolution=$(echo "$output" | jq -r '.SPDisplaysDataType[0].spdisplays_ndrvs[] | select(.spdisplays_online == "spdisplays_yes") | ._spdisplays_resolution') width=$(echo "$resolution" | jq -Rr 'split(" x ")[0]') From 7b4b1d631227f3a009a025a861cf5e92cbc4689f Mon Sep 17 00:00:00 2001 From: Petros Amoiridis Date: Thu, 20 Apr 2023 20:06:33 +0300 Subject: [PATCH 4/6] Use regex to make extraction bulletproof --- script/start-local-collaboration | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/start-local-collaboration b/script/start-local-collaboration index 7a94982a5a..5ac440eda2 100755 --- a/script/start-local-collaboration +++ b/script/start-local-collaboration @@ -33,9 +33,9 @@ fi # Make each Zed instance take up half of the screen. output=$(system_profiler SPDisplaysDataType -json) resolution=$(echo "$output" | jq -r '.SPDisplaysDataType[0].spdisplays_ndrvs[] | select(.spdisplays_online == "spdisplays_yes") | ._spdisplays_resolution') -width=$(echo "$resolution" | jq -Rr 'split(" x ")[0]') +width=$(echo "$resolution" | jq -Rr 'match("(\\d+) x (\\d+)").captures[0].string') half_width=$(($width / 2)) -height=$(echo "$resolution" | jq -Rr 'split(" x ")[1]') +height=$(echo "$resolution" | jq -Rr 'match("(\\d+) x (\\d+)").captures[1].string') y=0 echo "Width: $width" From 3c54b14c5b8d8ec6130cb8c1284c4450903c7521 Mon Sep 17 00:00:00 2001 From: Petros Amoiridis Date: Fri, 21 Apr 2023 17:17:04 +0300 Subject: [PATCH 5/6] Remove debugging information --- script/start-local-collaboration | 4 ---- 1 file changed, 4 deletions(-) diff --git a/script/start-local-collaboration b/script/start-local-collaboration index 5ac440eda2..c71200f488 100755 --- a/script/start-local-collaboration +++ b/script/start-local-collaboration @@ -38,10 +38,6 @@ half_width=$(($width / 2)) height=$(echo "$resolution" | jq -Rr 'match("(\\d+) x (\\d+)").captures[1].string') y=0 -echo "Width: $width" -echo "Half-width: $half_width" -echo "Height: $height" - position_1=0,${y} position_2=${half_width},${y} From 65c5605e683e3294b4c050cdf951dd36103675c0 Mon Sep 17 00:00:00 2001 From: Petros Amoiridis Date: Fri, 21 Apr 2023 17:18:01 +0300 Subject: [PATCH 6/6] Look for the main display always --- script/start-local-collaboration | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script/start-local-collaboration b/script/start-local-collaboration index c71200f488..b8632c4c22 100755 --- a/script/start-local-collaboration +++ b/script/start-local-collaboration @@ -32,7 +32,8 @@ fi # Make each Zed instance take up half of the screen. output=$(system_profiler SPDisplaysDataType -json) -resolution=$(echo "$output" | jq -r '.SPDisplaysDataType[0].spdisplays_ndrvs[] | select(.spdisplays_online == "spdisplays_yes") | ._spdisplays_resolution') +main_display=$(echo "$output" | jq '.SPDisplaysDataType[].spdisplays_ndrvs[] | select(.spdisplays_main == "spdisplays_yes")') +resolution=$(echo "$main_display" | jq -r '._spdisplays_resolution') width=$(echo "$resolution" | jq -Rr 'match("(\\d+) x (\\d+)").captures[0].string') half_width=$(($width / 2)) height=$(echo "$resolution" | jq -Rr 'match("(\\d+) x (\\d+)").captures[1].string')