diff --git a/main.js b/main.js index 7e04c27..99da7a4 100644 --- a/main.js +++ b/main.js @@ -231,12 +231,12 @@ async function scheduleWithHub(multiaddr) { } } -async function handlePPPPPUri(uri) { +async function handlePPPPPUri(ev, uri) { if (!globalAccountID) { - setTimeout(handlePPPPPUri, 100, uri) + setTimeout(handlePPPPPUri, 100, null, uri) return } - if (!uri.startsWith('ppppp://')) return + if (!uri.startsWith('ppppp://')) return console.log('Not a ppppp:// URI', uri) const commands = peer.invite.parse(uri) for (const command of commands) { console.log('Executing command', JSON.stringify(command)) @@ -296,7 +296,7 @@ if (!hasLock) { if (mainWindow.isMinimized()) mainWindow.restore() mainWindow.focus() if (argv.length > 1) { - handlePPPPPUri(argv[argv.length - 1]) + handlePPPPPUri(null, argv[argv.length - 1]) } } }) @@ -307,10 +307,11 @@ if (!hasLock) { ipcMain.handle('createInvite', createInvite) ipcMain.handle('copyToClipboard', copyToClipboard) ipcMain.handle('writeElements', writeElements) + ipcMain.handle('consumeInvite', handlePPPPPUri) ipcMain.handle('subscribeToReadElements', subscribeToReadElements) createWindow() if (process.argv.length > 1) { - handlePPPPPUri(process.argv[process.argv.length - 1]) + handlePPPPPUri(null, process.argv[process.argv.length - 1]) } app.on('activate', function () { diff --git a/preload.js b/preload.js index f9f75e5..65116de 100644 --- a/preload.js +++ b/preload.js @@ -4,6 +4,7 @@ contextBridge.exposeInMainWorld('electronAPI', { loadAccount: () => ipcRenderer.invoke('loadAccount'), createInvite: () => ipcRenderer.invoke('createInvite'), copyToClipboard: (text) => ipcRenderer.invoke('copyToClipboard', text), + consumeInvite: (text) => ipcRenderer.invoke('consumeInvite', text), setProfileName: (name) => ipcRenderer.invoke('setProfileName', name), writeElements: (actions) => ipcRenderer.invoke('writeElements', actions), onReadElements: (callback) => { diff --git a/src/App.js b/src/App.js index 50666e1..698b398 100644 --- a/src/App.js +++ b/src/App.js @@ -3,7 +3,9 @@ import { Excalidraw } from '@excalidraw/excalidraw' import debounce from 'debounce' import MyAccount from './MyAccount' import Button from './Button' +import GreenButton from './GreenButton' import CreateInviteModal from './CreateInviteModal' +import JoinModal from './JoinModal' import './App.css' const elemsPersisted = new Map() @@ -11,11 +13,17 @@ let sceneInitialized = false function App() { const [excalidrawAPI, setExcalidrawAPI] = useState(null) - const [inviteModalOpen, setInviteModalOpen] = useState(false) + const [inviteCode, setInviteCode] = useState(null) + + const [inviteModalOpen, setInviteModalOpen] = useState(false) const openInviteModal = () => setInviteModalOpen(true) const closeInviteModal = () => setInviteModalOpen(false) + const [joinModalOpen, setJoinModalOpen] = useState(false) + const openJoinModal = () => setJoinModalOpen(true) + const closeJoinModal = () => setJoinModalOpen(false) + function loadExcalidraw(api) { if (excalidrawAPI) return setExcalidrawAPI(api) @@ -40,6 +48,10 @@ function App() { }) } + function join() { + openJoinModal() + } + const updateElements = debounce((elems) => { if (!sceneInitialized) return const actions = [] @@ -59,7 +71,10 @@ function App() {
+
+
+ Join
+
) } diff --git a/src/GreenButton.js b/src/GreenButton.js new file mode 100644 index 0000000..31df65d --- /dev/null +++ b/src/GreenButton.js @@ -0,0 +1,14 @@ +function Button({ children, onClick, disabled }) { + return ( + + ) +} + +export default Button diff --git a/src/JoinModal.js b/src/JoinModal.js new file mode 100644 index 0000000..467a081 --- /dev/null +++ b/src/JoinModal.js @@ -0,0 +1,33 @@ +import { useState } from 'react' +import GreenButton from './GreenButton' +import Modal from './Modal' + +function JoinModal({ isOpen, onClose }) { + const [code, setCode] = useState('') + + function updateCode(ev) { + setCode(ev.target.value) + } + + function submitCode() { + window.electronAPI.consumeInvite(code) + queueMicrotask(onClose) + } + + return ( + + Insert here the ppppp:// invite code you received from your friend. +