Skip to content

Commit

Permalink
Id webpage (#54)
Browse files Browse the repository at this point in the history
* update idpage

* link add friend!!

* public id link should work

* finish

* fix things
  • Loading branch information
arvid220u authored Jul 28, 2022
1 parent 385b9dd commit e56fea0
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 22 deletions.
2 changes: 1 addition & 1 deletion daemon/crypto/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ constexpr auto DEFAULT_ROUND_DELAY_SECONDS = 60;
constexpr auto DEFAULT_SERVER_ADDRESS = "server1.anysphere.co:443";

// this commit hash will be automatically updated by gui/package.json.
constexpr auto RELEASE_COMMIT_HASH = "e1e606952ff47d097718dee42cd922edcf7782f6";
constexpr auto RELEASE_COMMIT_HASH = "d5e0ce2ccb86796ed58b0b66fb38665b6c7a64e9";

// this is the number of friends that will be received from in each round
// (ideally, they can all be received in a single PIR request using batch PIR)
Expand Down
8 changes: 8 additions & 0 deletions gui/helpers/scripts/package-mac-dmg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ const config = {
}
},

protocols: [
{
name: "Anysphere URL",
schemes: ["anysphere"],
role: "Editor",
},
],

mac: {
target: {
target: "default",
Expand Down
2 changes: 1 addition & 1 deletion gui/src/main/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { exit } from "process";
import path from "path";

// this commit hash will be automatically updated by gui/package.json.
export const RELEASE_COMMIT_HASH = "e1e606952ff47d097718dee42cd922edcf7782f6";
export const RELEASE_COMMIT_HASH = "d5e0ce2ccb86796ed58b0b66fb38665b6c7a64e9";

export const PLIST_PATH = () => {
if (process.platform === "darwin" && process.env.HOME) {
Expand Down
40 changes: 37 additions & 3 deletions gui/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
//

import path from "path";
import { app, BrowserWindow, session, shell, Notification } from "electron";
import {
app,
dialog,
BrowserWindow,
session,
shell,
Notification,
} from "electron";
import MenuBuilder from "./menu";
import { resolveHtmlPath } from "./util";
import { autoUpdater } from "electron-updater";
Expand All @@ -31,6 +38,16 @@ if (process.env["NODE_ENV"] === "production") {
sourceMapSupport.install();
}

if (process.defaultApp) {
if (process.argv.length >= 2 && process.argv[1] != null) {
app.setAsDefaultProtocolClient("anysphere", process.execPath, [
path.resolve(process.argv[1]),
]);
}
} else {
app.setAsDefaultProtocolClient("anysphere");
}

function setupLogger(): void {
let logPath = "";
if (process.env["XDG_CACHE_HOME"] !== undefined) {
Expand Down Expand Up @@ -139,7 +156,7 @@ async function installExtensions(): Promise<void> {
.catch(logger.log);
}

const createWindow = async () => {
const createWindow = async (publicID?: string): Promise<void> => {
if (isDevelopment) {
await installExtensions();
}
Expand Down Expand Up @@ -168,7 +185,12 @@ const createWindow = async () => {
},
});

mainWindow.loadURL(resolveHtmlPath("index.html"));
let loadURL = resolveHtmlPath("index.html");
if (publicID != null) {
loadURL = resolveHtmlPath(`index.html?publicID=${publicID}`);
}

mainWindow.loadURL(loadURL);

mainWindow.on("ready-to-show", () => {
if (process.env["START_MINIMIZED"] === "true") {
Expand Down Expand Up @@ -270,3 +292,15 @@ app.on("web-contents-created", (event, contents) => {
shell.openExternal(navigationUrl);
});
});

// Handle the protocol. In this case, we choose to show an Error Box.
app.on("open-url", (event, url) => {
const publicID = url.split("/").pop();
if (BrowserWindow.getAllWindows().length === 0) {
createWindow(publicID);
} else {
BrowserWindow.getAllWindows()[0].loadURL(
resolveHtmlPath("index.html?publicID=" + publicID)
);
}
});
38 changes: 35 additions & 3 deletions gui/src/renderer/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,31 @@ const defaultTabs: Tab[] = [
{ type: TabType.All, name: "All", data: null, unclosable: true, id: "all" },
];

function MainWrapper(): JSX.Element {
function MainWrapper({
initialModal,
initialModalData,
}: {
initialModal?: InitialModal;
initialModalData: unknown;
}): JSX.Element {
return (
<StatusHandler>
<Main />
<Main initialModal={initialModal} initialModalData={initialModalData} />
</StatusHandler>
);
}

function Main(): JSX.Element {
export enum InitialModal {
AddFriendByPublicId,
}

function Main({
initialModal,
initialModalData,
}: {
initialModal?: InitialModal;
initialModalData: unknown;
}): JSX.Element {
const [
selectedTab,
tabs,
Expand Down Expand Up @@ -118,6 +134,22 @@ function Main(): JSX.Element {
setModal(null);
}, [setModal]);

React.useEffect(() => {
if (initialModal === InitialModal.AddFriendByPublicId) {
setModal(
<AddFriend
onClose={closeModal}
setStatus={(x) => {
statusState.setStatus(x);
statusState.setVisible();
}}
initialScreen={AddFriendScreen.RemotePartTwo}
theirPublicId={initialModalData as string}
/>
);
}
}, [closeModal, statusState, initialModal, initialModalData]);

const openFriendModal = React.useCallback(() => {
setModal(
<AddFriend
Expand Down
4 changes: 3 additions & 1 deletion gui/src/renderer/components/AddFriend/AddFriend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ export default function AddFriend({
setStatus,
initialScreen,
incomingInvitation,
theirPublicId,
}: {
onClose: () => void;
setStatus: (status: StatusProps) => void;
initialScreen?: AddFriendScreen;
incomingInvitation?: IncomingAsyncInvitation;
theirPublicId?: string;
}): JSX.Element {
const [screen, setScreen] = React.useState<AddFriendScreen>(
initialScreen ?? AddFriendScreen.Choice
);
const [story, setStory] = React.useState<string>("");
const [publicID, setPublicID] = React.useState<string>("");
const [theirID, setTheirID] = React.useState<string>("");
const [theirID, setTheirID] = React.useState<string>(theirPublicId ?? "");

React.useEffect(() => {
window
Expand Down
21 changes: 18 additions & 3 deletions gui/src/renderer/components/AddFriend/AddFriendRemote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { StatusProps } from "../Status";
import { classNames } from "../../utils";
import { useEffect, useState } from "react";
import { IDAnimation } from "./IDAnimation";
import { truncate } from "../../utils";

const DEBUG_COLORS = false;
// const DEBUG_COLORS = true;
Expand Down Expand Up @@ -84,9 +85,23 @@ export default function AddFriendRemote({
<IDAnimation seed={publicId} bordersize={4} />
</div>
<div></div>
<h2 className="text-xs" style={{ userSelect: "text" }}>
anysphere.id/#{publicId}
</h2>
<div className="flex h-fit flex-row items-center gap-4">
<h2 className="text-xl font-bold" style={{ userSelect: "text" }}>
anysphere.id/#{truncate(publicId, 12)}
</h2>
<button
className="unselectable rounded-lg bg-asbrown-100 px-3 py-1 text-asbrown-light"
onClick={() => {
window.copyToClipboard(`https://anysphere.id/#${publicId}`);
setStatus({
message: "Copied to clipboard.",
actionName: null,
});
}}
>
Copy
</button>
</div>
<div></div>
<div></div>
<div></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ export default function AddFriendRemotePartTwo({
);
}
}}
onKeyDown={(e) => {
if (e.key === "Enter") {
setProgress(1);
}
}}
value={displayName}
placeholder="First Last"
/>
Expand Down
11 changes: 2 additions & 9 deletions gui/src/renderer/components/AddFriend/IDAnimation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
//

import seedrandom from "seedrandom";
import { motion } from "framer-motion";
import { useState, useEffect, useMemo } from "react";
import { classNames } from "../../utils";
import { sha256string, randint } from "./utils";

const DEBUG_COLORS = false;
// const DEBUG_COLORS = true;
import React from "react"; // needed for idpage

// IDAnimation is used to provide a visual version of the public ID string.
// It has the following requirements:
Expand Down Expand Up @@ -88,10 +84,7 @@ export function IDAnimation({
return (
<>
<div
className={classNames(
"absolute h-full w-full overflow-clip rounded-full",
DEBUG_COLORS ? "bg-green-100" : ""
)}
className="absolute h-full w-full overflow-clip rounded-full"
style={{
backgroundColor: background,
willChange: "opacity",
Expand Down
20 changes: 19 additions & 1 deletion gui/src/renderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@

import { render } from "react-dom";
import Main from "./Main";
import { InitialModal } from "./Main";
import "./index.css";

render(<Main />, document.getElementById("root"));
// get path
const url = new URL(window.location.href);
const params = new URLSearchParams(url.search);
const publicID = params.get("publicID");

let component;
if (publicID != null) {
component = (
<Main
initialModal={InitialModal.AddFriendByPublicId}
initialModalData={publicID}
/>
);
} else {
component = <Main />;
}

render(component, document.getElementById("root"));

0 comments on commit e56fea0

Please sign in to comment.