Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Register studio as a url handler for foxglove:// files #604

Merged
merged 2 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/OsContext.ts
Expand Up @@ -77,6 +77,9 @@ export interface OsContext {
// Get the version string from package.json
getAppVersion: () => string;

// Get an array of deep links provided on app launch
getDeepLinks: () => string[];

// file backed key/value storage
storage: Storage;
}
29 changes: 29 additions & 0 deletions app/components/PlayerManager.tsx
Expand Up @@ -14,6 +14,7 @@
import { PropsWithChildren, useCallback, useEffect, useMemo, useRef, useState } from "react";
import { connect, ConnectedProps } from "react-redux";
import { useAsync, useLocalStorage, useMountedState } from "react-use";
import { URL } from "universal-url";

import OsContextSingleton from "@foxglove-studio/app/OsContextSingleton";
import {
Expand Down Expand Up @@ -423,6 +424,34 @@ function PlayerManager({
}
}, []);

useEffect(() => {
const links = OsContextSingleton?.getDeepLinks() ?? [];
const firstLink = links[0];
if (firstLink == undefined) {
return;
}

try {
const url = new URL(firstLink);
// only support the open command

// Test if the pathname matches //open or //open/
if (!/\/\/open\/?/.test(url.pathname)) {
return;
}

// only support rosbag urls
const type = url.searchParams.get("type");
const bagUrl = url.searchParams.get("url");
if (type !== "rosbag" || bagUrl == undefined) {
return;
}
setPlayer(async (options: BuildPlayerOptions) => buildPlayerFromBagURLs([bagUrl], options));
} catch (err) {
log.error(err);
}
}, [setPlayer]);

// The first time we load a source, we restore the previous source state (i.e. url)
// and try to automatically load the source.
// Subsequent source changes do not restore the state which typically results in a user prompt
Expand Down