-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: handle multiple previews at the same time #421
Conversation
Test this pull request on windows-latestDownload the correct version for your architecture: |
Test this pull request on macos-latestDownload the correct version for your architecture:Click here if you don't know which version to downloadFor running this unsigned version of the app, you will need to run the xattr command on it:
|
} | ||
} catch (_) { | ||
missing.push(_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it going to enter here when the fs.readdir
throws an error?
In that case, should we skip the path because it isn't accessible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was following the same approach as the code does when the path doesn't exist or its unaccessible.
if (!(await exists(_path))) {
// _path doesn't exist
missing.push(_path);
cb24199
to
606bddc
Compare
@@ -22,24 +22,41 @@ export async function init(path: string, repo?: string) { | |||
await initCommand.wait(); | |||
} | |||
|
|||
export let previewServer: Child | null = null; | |||
export async function killPreview(path: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think of something like this? just replaced the cache with a Map and added some types
interface PreviewData {
child: Child;
previewURL: string;
}
export const previewCache = new Map<string, PreviewData>();
export async function killPreview(path: string) {
const preview = previewCache.get(path);
if (preview?.child) {
await preview.child.kill().catch(() => {});
}
previewCache.delete(path);
}
export async function killAllPreviews(): Promise<void> {
const killPromises: Promise<void>[] = [];
for (const preview of previewCache.values()) {
killPromises.push(preview.child.kill().catch(() => {}));
}
await Promise.all(killPromises);
previewCache.clear();
}
async function createPreviewProcess(path: string): Promise<PreviewData> {
const child = run('@dcl/sdk-commands', 'sdk-commands', {
args: ['start', '--explorer-alpha', '--hub'],
cwd: path,
workspace: path,
env: await getEnv(path),
});
const dclLauncherURL = /decentraland:\/\/([^\s\n]*)/i;
const resultLogs = await child.waitFor(dclLauncherURL, /CliError/i);
const urlMatch = resultLogs.match(dclLauncherURL);
return {
child,
previewURL: urlMatch?.[1] ?? '',
};
}
export async function start(path: string, retry = true) {
try {
const existingPreview = previewCache.get(path);
if (existingPreview?.child.alive() && existingPreview.previewURL) {
await dclDeepLink(existingPreview.previewURL);
return;
}
await killPreview(path);
const preview = await createPreviewProcess(path);
previewCache.set(path, preview);
} catch (error) {
previewCache.delete(path);
if (retry) {
log.info('[CLI] Something went wrong trying to start preview:', (error as Error).message);
await install(path);
await start(path, false);
} else {
throw error;
}
}
}
and replace killPreview
with killAllPreview
on packages/main/src/index.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats the diff between a map and a record ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving everything to diff functions that only are used 1 time feels unnecessary imo
packages/main/src/modules/bin.ts
Outdated
@@ -405,6 +405,14 @@ async function handleData(buffer: Buffer, matchers: Matcher[], type: StreamType) | |||
} | |||
} | |||
|
|||
export async function dclDeepLink(deepLink: string) { | |||
try { | |||
await exec(`open decentraland://"${deepLink}"`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in Windows we have to use start "decentraland://${deepLink}"
, does the exec
handle it automatically for each OS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YES !!!!!!!!!!!!!!! that was a TODO that totally forgot about! thanks gabi
also error handling when importing scene and its not accesible