Make zed-local support opening 5 or 6 zed instances
This commit is contained in:
parent
e992f84735
commit
77fc332d6f
2 changed files with 43 additions and 23 deletions
|
@ -1 +1,8 @@
|
||||||
["nathansobo", "as-cii", "maxbrunsfeld", "iamnbutler"]
|
[
|
||||||
|
"nathansobo",
|
||||||
|
"as-cii",
|
||||||
|
"maxbrunsfeld",
|
||||||
|
"iamnbutler",
|
||||||
|
"mikayla-maki",
|
||||||
|
"JosephTLyons"
|
||||||
|
]
|
||||||
|
|
|
@ -5,15 +5,15 @@ USAGE
|
||||||
zed-local [options] [zed args]
|
zed-local [options] [zed args]
|
||||||
|
|
||||||
SUMMARY
|
SUMMARY
|
||||||
Runs 1-4 instances of Zed using a locally-running collaboration server.
|
Runs 1-6 instances of Zed using a locally-running collaboration server.
|
||||||
Each instance of Zed will be signed in as a different user specified in
|
Each instance of Zed will be signed in as a different user specified in
|
||||||
either \`.admins.json\` or \`.admins.default.json\`.
|
either \`.admins.json\` or \`.admins.default.json\`.
|
||||||
|
|
||||||
OPTIONS
|
OPTIONS
|
||||||
--help Print this help message
|
--help Print this help message
|
||||||
--release Build Zed in release mode
|
--release Build Zed in release mode
|
||||||
-2, -3, -4 Spawn 2, 3, or 4 Zed instances, with their windows tiled.
|
-2, -3, -4, ... Spawn multiple Zed instances, with their windows tiled.
|
||||||
--top Arrange the Zed windows so they take up the top half of the screen.
|
--top Arrange the Zed windows so they take up the top half of the screen.
|
||||||
`.trim();
|
`.trim();
|
||||||
|
|
||||||
const { spawn, execFileSync } = require("child_process");
|
const { spawn, execFileSync } = require("child_process");
|
||||||
|
@ -25,7 +25,9 @@ try {
|
||||||
const customUsers = require("../crates/collab/.admins.json");
|
const customUsers = require("../crates/collab/.admins.json");
|
||||||
assert(customUsers.length > 0);
|
assert(customUsers.length > 0);
|
||||||
assert(customUsers.every((user) => typeof user === "string"));
|
assert(customUsers.every((user) => typeof user === "string"));
|
||||||
users.splice(0, 0, ...customUsers);
|
users = customUsers.concat(
|
||||||
|
defaultUsers.filter((user) => !customUsers.includes(user)),
|
||||||
|
);
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
|
||||||
const RESOLUTION_REGEX = /(\d+) x (\d+)/;
|
const RESOLUTION_REGEX = /(\d+) x (\d+)/;
|
||||||
|
@ -77,28 +79,34 @@ if (isTop) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine the window size for each instance
|
// Determine the window size for each instance
|
||||||
let instanceWidth = screenWidth;
|
let rows;
|
||||||
let instanceHeight = screenHeight;
|
let columns;
|
||||||
if (instanceCount > 1) {
|
switch (instanceCount) {
|
||||||
instanceWidth = Math.floor(screenWidth / 2);
|
case 1:
|
||||||
if (instanceCount > 2) {
|
[rows, columns] = [1, 1];
|
||||||
instanceHeight = Math.floor(screenHeight / 2);
|
break;
|
||||||
}
|
case 2:
|
||||||
|
[rows, columns] = [1, 2];
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
[rows, columns] = [2, 2];
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
case 6:
|
||||||
|
[rows, columns] = [2, 3];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const instanceWidth = Math.floor(screenWidth / columns);
|
||||||
|
const instanceHeight = Math.floor(screenHeight / rows);
|
||||||
|
|
||||||
// If a user is specified, make sure it's first in the list
|
// If a user is specified, make sure it's first in the list
|
||||||
const user = process.env.ZED_IMPERSONATE;
|
const user = process.env.ZED_IMPERSONATE;
|
||||||
if (user) {
|
if (user) {
|
||||||
users = [user].concat(users.filter((u) => u !== user));
|
users = [user].concat(users.filter((u) => u !== user));
|
||||||
}
|
}
|
||||||
|
|
||||||
const positions = [
|
|
||||||
"0,0",
|
|
||||||
`${instanceWidth},0`,
|
|
||||||
`0,${instanceHeight}`,
|
|
||||||
`${instanceWidth},${instanceHeight}`,
|
|
||||||
];
|
|
||||||
|
|
||||||
let buildArgs = ["build"];
|
let buildArgs = ["build"];
|
||||||
let zedBinary = "target/debug/Zed";
|
let zedBinary = "target/debug/Zed";
|
||||||
if (isReleaseMode) {
|
if (isReleaseMode) {
|
||||||
|
@ -109,16 +117,21 @@ if (isReleaseMode) {
|
||||||
execFileSync("cargo", buildArgs, { stdio: "inherit" });
|
execFileSync("cargo", buildArgs, { stdio: "inherit" });
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
for (let i = 0; i < instanceCount; i++) {
|
for (let i = 0; i < instanceCount; i++) {
|
||||||
|
const row = Math.floor(i / columns);
|
||||||
|
const column = i % columns;
|
||||||
|
const position = [column * instanceWidth, row * instanceHeight].join(",");
|
||||||
|
const size = [instanceWidth, instanceHeight].join(",");
|
||||||
|
|
||||||
spawn(zedBinary, i == 0 ? args : [], {
|
spawn(zedBinary, i == 0 ? args : [], {
|
||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
env: {
|
env: {
|
||||||
ZED_IMPERSONATE: users[i],
|
ZED_IMPERSONATE: users[i],
|
||||||
ZED_WINDOW_POSITION: positions[i],
|
ZED_WINDOW_POSITION: position,
|
||||||
ZED_STATELESS: "1",
|
ZED_STATELESS: "1",
|
||||||
ZED_ALWAYS_ACTIVE: "1",
|
ZED_ALWAYS_ACTIVE: "1",
|
||||||
ZED_SERVER_URL: "http://localhost:8080",
|
ZED_SERVER_URL: "http://localhost:8080",
|
||||||
ZED_ADMIN_API_TOKEN: "secret",
|
ZED_ADMIN_API_TOKEN: "secret",
|
||||||
ZED_WINDOW_SIZE: `${instanceWidth},${instanceHeight}`,
|
ZED_WINDOW_SIZE: size,
|
||||||
PATH: process.env.PATH,
|
PATH: process.env.PATH,
|
||||||
RUST_LOG: process.env.RUST_LOG || "info",
|
RUST_LOG: process.env.RUST_LOG || "info",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue