-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/invite-event-handling
- Loading branch information
Showing
13 changed files
with
751 additions
and
75 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
array, | ||
object, | ||
optional, | ||
parse, | ||
string, | ||
undefined, | ||
union, | ||
} from 'valibot' | ||
|
||
const FilesSelectParamsSchema = union([ | ||
object({ | ||
extensionFilters: optional(array(string())), | ||
}), | ||
undefined(), | ||
]) | ||
|
||
export const APP_IPC_EVENT_TO_PARAMS_PARSER = /** @type {const} */ ({ | ||
/** | ||
* @param {unknown} value | ||
* | ||
* @returns {import('valibot').InferOutput<typeof FilesSelectParamsSchema>} | ||
*/ | ||
'files:select': (value) => { | ||
return parse(FilesSelectParamsSchema, value) | ||
}, | ||
}) | ||
|
||
/** @typedef {keyof typeof APP_IPC_EVENT_TO_PARAMS_PARSER} AppIPCEvents */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,43 @@ | ||
const { contextBridge, ipcRenderer } = require('electron/renderer') | ||
|
||
// We need to wait until the main world is ready to receive the message before | ||
// sending the port. We create this promise in the preload so it's guaranteed | ||
// to register the onload listener before the load event is fired. | ||
const windowLoaded = new Promise((resolve) => { | ||
window.onload = resolve | ||
}) | ||
window.onmessage = (event) => { | ||
// event.source === window means the message is coming from the preload | ||
// script, as opposed to from an <iframe> or other source. | ||
if (event.source !== window) return | ||
if (event.data !== 'comapeo-port') return | ||
const [port] = event.ports | ||
if (!port) return // TODO: throw/report error | ||
ipcRenderer.postMessage('comapeo-port', null, [port]) | ||
} | ||
|
||
/** | ||
* @type {import('./runtime.js').RuntimeApi} | ||
*/ | ||
const runtimeApi = { | ||
// Setup | ||
init() { | ||
ipcRenderer.send('request-comapeo-port') | ||
ipcRenderer.once('provide-comapeo-port', async (event) => { | ||
await windowLoaded | ||
window.postMessage('comapeo-port', '*', event.ports) | ||
}) | ||
}, | ||
|
||
// Locale | ||
async getLocale() { | ||
const locale = await ipcRenderer.invoke('locale:get') | ||
if (typeof locale !== 'string') throw Error('Locale must be a string') | ||
if (typeof locale !== 'string') { | ||
throw new Error('Locale must be a string') | ||
} | ||
return locale | ||
}, | ||
updateLocale(locale) { | ||
ipcRenderer.send('locale:update', locale) | ||
}, | ||
|
||
// Files | ||
async selectFile(extensionFilters) { | ||
const filePath = await ipcRenderer.invoke('files:select', { | ||
extensionFilters, | ||
}) | ||
|
||
if (!(typeof filePath === 'string' || typeof filePath === 'undefined')) { | ||
throw new Error(`File path is unexpected type: ${typeof filePath}`) | ||
} | ||
|
||
return filePath | ||
}, | ||
} | ||
|
||
contextBridge.exposeInMainWorld('runtime', runtimeApi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export type RuntimeApi = { | ||
init: () => void | ||
getLocale: () => Promise<string> | ||
updateLocale: (locale: string) => void | ||
selectFile: (extensionFilters?: Array<string>) => Promise<string | undefined> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createMapeoClient } from '@comapeo/ipc' | ||
|
||
export function initComapeoClient() { | ||
const { port1, port2 } = new MessageChannel() | ||
window.postMessage('comapeo-port', '*', [port2]) | ||
const client = createMapeoClient(port1, { timeout: Infinity }) | ||
port1.start() | ||
return client | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Map as ReactMapLibre } from '@vis.gl/react-maplibre' | ||
|
||
import 'maplibre-gl/dist/maplibre-gl.css' | ||
|
||
export function Map() { | ||
const center = [-72.312023, -10.38787] | ||
|
||
return ( | ||
<ReactMapLibre | ||
initialViewState={{ | ||
longitude: center[0], | ||
latitude: center[1], | ||
zoom: 6, | ||
}} | ||
dragPan={true} | ||
scrollZoom={true} | ||
doubleClickZoom={true} | ||
style={{ width: '100%', height: '100%' }} | ||
mapStyle="https://demotiles.maplibre.org/style.json" | ||
onError={(evt) => { | ||
console.error('Map error:', evt.error) | ||
}} | ||
onLoad={() => { | ||
console.log('Map loaded successfully!') | ||
}} | ||
/> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useMutation } from '@tanstack/react-query' | ||
|
||
/** | ||
* If the resolved value is `undefined` that means the user did not select a | ||
* file (i.e. cancelled the selection dialog) | ||
*/ | ||
export function useSelectProjectConfigFile() { | ||
return useMutation({ | ||
mutationFn: async () => { | ||
return window.runtime.selectFile(['comapeocat']) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters