Skip to content

Commit

Permalink
Move from app package to desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvicenti committed Jun 25, 2024
1 parent cb21303 commit fcb0ba2
Show file tree
Hide file tree
Showing 347 changed files with 3,707 additions and 2,980 deletions.
10 changes: 10 additions & 0 deletions frontend/apps/desktop/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ declare const MAIN_WINDOW_VITE_DEV_SERVER_URL: string
declare const MAIN_WINDOW_VITE_NAME: string
declare const FIND_IN_PAGE_VITE_DEV_SERVER_URL: string
declare const FIND_IN_PAGE_VITE_NAME: string

interface ImportMetaEnv {
readonly VITE_HTTP_PORT: string
readonly VITE_GRPC_PORT: string
readonly VITE_P2P_PORT: string
}

interface ImportMeta {
readonly env: ImportMetaEnv
}
70 changes: 69 additions & 1 deletion frontend/apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,93 @@
"@ariakit/react": "0.3.5",
"@bufbuild/protobuf": "^1.10.0",
"@connectrpc/connect-web": "1.1.3",
"@dnd-kit/core": "^6.1.0",
"@dnd-kit/sortable": "^8.0.0",
"@electron-forge/maker-dmg": "7.1.0",
"@electron-forge/maker-rpm": "7.1.0",
"@emotion/cache": "11.11.0",
"@emotion/react": "11.11.1",
"@emotion/serialize": "1.1.2",
"@emotion/utils": "1.2.1",
"@hookform/resolvers": "3.3.1",
"@juggle/resize-observer": "3.4.0",
"@mantine/core": "6.0.13",
"@mantine/hooks": "6.0.13",
"@manuscripts/prosemirror-recreate-steps": "^0.1.4",
"@radix-ui/colors": "0.1.9",
"@radix-ui/react-dropdown-menu": "2.0.5",
"@sentry/electron": "4.7.0",
"@sentry/tracing": "7.49.0",
"@sentry/vite-plugin": "latest",
"@shm/app": "*",
"@shm/prettier": "*",
"@shm/shared": "*",
"@shm/ui": "*",
"@tanstack/react-query": "4.33.0",
"@tanstack/react-query-devtools": "4.33.0",
"@tippyjs/react": "4.2.6",
"@tiptap/core": "2.0.3",
"@tiptap/extension-bold": "2.0.3",
"@tiptap/extension-code": "2.0.3",
"@tiptap/extension-collaboration": "2.0.3",
"@tiptap/extension-collaboration-cursor": "2.0.3",
"@tiptap/extension-dropcursor": "2.0.3",
"@tiptap/extension-gapcursor": "2.0.3",
"@tiptap/extension-hard-break": "2.0.3",
"@tiptap/extension-history": "2.0.3",
"@tiptap/extension-italic": "2.0.3",
"@tiptap/extension-strike": "2.0.3",
"@tiptap/extension-text": "2.0.3",
"@tiptap/extension-underline": "2.0.3",
"@tiptap/pm": "2.0.3",
"@tiptap/react": "2.0.3",
"@trpc/client": "10.40.0",
"@trpc/react-query": "10.40.0",
"@trpc/server": "10.40.0",
"@xstate/react": "beta",
"allotment": "1.18.1",
"cheerio": "1.0.0-rc.12",
"console-log-colors": "0.4.0",
"electron-context-menu": "3.6.1",
"electron-log": "beta",
"electron-squirrel-startup": "1.0.0",
"electron-store": "8.1.0",
"electron-trpc": "0.5.2",
"fast-deep-equal": "^3.1.3",
"fs-extra": "11.1.1",
"graphql-request": "6.0.0",
"hast-util-from-dom": "4.2.0",
"highlight.js": "11.9.0",
"katex": "^0.16.9",
"linkifyjs": "4.1.1",
"lowlight": "3.1.0",
"lz-string": "1.5.0",
"match-sorter": "6.3.1",
"nanoid": "4.0.2",
"nostr-tools": "1.16.0",
"prom-client": "15.1.0",
"prosemirror-state": "1.4.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-error-boundary": "4.0.11",
"react-hook-form": "7.46.1",
"react-icons": "4.9.0",
"react-tweet": "^3.2.0",
"rehype": "12.0.1",
"rehype-parse": "8.0.4",
"rehype-remark": "9.1.2",
"rehype-stringify": "9.0.3",
"remark-gfm": "3.0.1",
"remark-parse": "10.0.1",
"remark-rehype": "10.1.0",
"remark-stringify": "10.0.2",
"unified": "10.1.2",
"use-prefers-color-scheme": "1.1.3",
"winston": "3.11.0",
"winston-daily-rotate-file": "4.7.1",
"xstate": "beta",
"y-prosemirror": "1.2.1",
"y-protocols": "1.0.5",
"yjs": "13.6.4",
"zod": "3.22.2"
},
"devDependencies": {
Expand All @@ -72,17 +131,26 @@
"@playwright/test": "1.40.1",
"@shm/prettier": "*",
"@tamagui/vite-plugin": "1.95.0",
"@types/node": "20.6.5",
"@types/prosemirror-dev-tools": "3.0.3",
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
"@vitejs/plugin-react": "4.0.4",
"copy-text-to-clipboard": "3.1.0",
"electron": "26.0.0",
"electron-playwright-helpers": "1.6.0",
"happy-dom": "7.8.1",
"jsdom": "22.1.0",
"loglevel": "1.8.1",
"prettier": "3.0.2",
"prosemirror-dev-tools": "4.0.0",
"react-devtools": "4.28.0",
"react-error-boundary": "4.0.11",
"tamagui": "1.95.0",
"typescript": "5.5.1-rc",
"vite": "4.4.9",
"vite-tsconfig-paths": "4.2.0",
"vitest": "0.34.2",
"xvfb-maybe": "0.2.1"
}
}
6 changes: 3 additions & 3 deletions frontend/apps/desktop/src/app-account.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useGRPCClient } from '@shm/app/app-context'
import { DialogTitle } from '@shm/app/components/dialog'
import { queryKeys } from '@shm/app/models/query-keys'
import { useGRPCClient } from '@shm/desktop/src/app-context'
import { DialogTitle } from '@shm/desktop/src/components/dialog'
import { queryKeys } from '@shm/desktop/src/models/query-keys'
import { eventStream } from '@shm/shared'
import {
Add,
Expand Down
13 changes: 9 additions & 4 deletions frontend/apps/desktop/src/app-api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import {resolveHmIdToAppRoute} from '@shm/app/utils/navigation'
import {NavRoute, defaultRoute, navRouteSchema} from '@shm/app/utils/routes'
import type {AppWindowEvent} from '@shm/app/utils/window-events'
import {API_GRPC_URL, API_HTTP_URL} from '@shm/shared'
import {resolveHmIdToAppRoute} from '@shm/desktop/src/utils/navigation'
import {
NavRoute,
defaultRoute,
navRouteSchema,
} from '@shm/desktop/src/utils/routes'
import type {AppWindowEvent} from '@shm/desktop/src/utils/window-events'
import {API_GRPC_URL, API_HTTP_URL} from '@shm/shared/src/constants'

import {
BrowserWindow,
NativeImage,
Expand Down
90 changes: 90 additions & 0 deletions frontend/apps/desktop/src/app-context-provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { GRPCClient } from '@shm/shared'
import { TamaguiProvider, TamaguiProviderProps, View } from '@shm/ui'
import { QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { ReactNode, useMemo } from 'react'

import tamaguiConfig from '../tamagui.config'
import { AppIPC } from './app-ipc'
import { useExperiments } from './models/experiments'

import { AppContext, AppPlatform } from './app-context'
import { WindowUtils } from './models/window-utils'
import { AppQueryClient } from './query-client'


export function AppContextProvider({
children,
platform,
grpcClient,
queryClient,
ipc,
externalOpen,
windowUtils,
saveCidAsFile,
darkMode,
}: {
children: ReactNode
platform: AppPlatform
grpcClient: GRPCClient
queryClient: AppQueryClient
ipc: AppIPC
externalOpen: (url: string) => Promise<void>
windowUtils: WindowUtils
saveCidAsFile: (cid: string, name: string) => Promise<void>
darkMode: boolean
}) {
const appCtx = useMemo(
() => ({
// platform: 'win32', // to test from macOS
platform,
grpcClient,
queryClient,
ipc,
externalOpen,
windowUtils,
saveCidAsFile,
}),
[],
)
if (!queryClient)
throw new Error('queryClient is required for AppContextProvider')
return (
<AppContext.Provider value={appCtx}>
<QueryClientProvider client={queryClient.client}>
<StyleProvider darkMode={darkMode}>{children}</StyleProvider>
<ReactQueryTools />
</QueryClientProvider>
</AppContext.Provider>
)
}

function ReactQueryTools() {
const { data: experiments } = useExperiments()
return experiments?.developerTools ? (
<View userSelect="none">
<ReactQueryDevtools />
</View>
) : null
}

export function StyleProvider({
children,
darkMode,
...rest
}: Omit<TamaguiProviderProps, 'config'> & { darkMode: boolean }) {
return (
<TamaguiProvider
// @ts-ignore
config={tamaguiConfig}
// TODO: find a way to add this props without breaking all the styles
// disableInjectCSS
// disableRootThemeClass
className={darkMode ? 'seed-app-dark' : 'seed-app-light'}
defaultTheme={darkMode ? 'dark' : 'light'}
{...rest}
>
{children}
</TamaguiProvider>
)
}
91 changes: 91 additions & 0 deletions frontend/apps/desktop/src/app-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { GRPCClient } from '@shm/shared'
import { createContext, useContext, useEffect } from 'react'

import { AppIPC, Event, EventCallback } from './app-ipc'

import { WindowUtils } from './models/window-utils'
import { AppQueryClient } from './query-client'


export type AppPlatform = typeof process.platform

export type AppContext = {
platform: AppPlatform
grpcClient: GRPCClient
queryClient: AppQueryClient
ipc: AppIPC
externalOpen: (url: string) => Promise<void>
windowUtils: WindowUtils
saveCidAsFile: (cid: string, name: string) => Promise<void>
}

export const AppContext = createContext<AppContext | null>(null)


export function useAppContext() {
const context = useContext(AppContext)
if (!context)
throw new Error('useAppContext must be used within a AppContextProvider')

return context
}

export function useGRPCClient(): GRPCClient {
const context = useContext(AppContext)
if (!context)
throw new Error('useGRPCClient must be used within a AppContextProvider')
return context.grpcClient
}

export function useIPC(): AppIPC {
const context = useContext(AppContext)
if (!context)
throw new Error('useIPC must be used within a AppContextProvider')

return context.ipc
}

export function useQueryInvalidator() {
const context = useContext(AppContext)
if (!context)
throw new Error(
'useQueryInvalidator must be used within a AppContextProvider',
)

return context.queryClient.invalidate
}

export function useWindowUtils(): WindowUtils {
const context = useContext(AppContext)
if (!context)
throw new Error('useWindowUtils must be used within a AppContextProvider')

return context.windowUtils
}

export function useListen<T = unknown>(
cmd: string,
handler: EventCallback<T>,
deps: React.DependencyList = [],
) {
const { listen } = useIPC()
useEffect(() => {
if (!listen) {
throw new Error('useListen called before listen is defined')
}
let isSubscribed = true
let unlisten: () => void

listen(cmd, (event: Event<T>) => {
if (!isSubscribed) {
return unlisten()
}

handler(event)
}).then((_unlisten) => (unlisten = _unlisten))

return () => {
isSubscribed = false
}
}, deps)
}
File renamed without changes.
6 changes: 3 additions & 3 deletions frontend/apps/desktop/src/app-menu.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// this menu is visible on macOS only
// the keyboard shortcuts apply to every platform

import { defaultRoute } from '@shm/app/utils/routes'
import { Menu, MenuItem } from 'electron'
import { dispatchFocusedWindowAppEvent, openRoute, trpc } from './app-api'
import {defaultRoute} from '@shm/desktop/src/utils/routes'
import {Menu, MenuItem} from 'electron'
import {dispatchFocusedWindowAppEvent, openRoute, trpc} from './app-api'

export function createAppMenu() {
const appMenu = new Menu()
Expand Down
2 changes: 1 addition & 1 deletion frontend/apps/desktop/src/app-recents.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NavRoute, getRecentsRouteEntityUrl} from '@shm/app/utils/routes'
import {NavRoute, getRecentsRouteEntityUrl} from '@shm/desktop/src/utils/routes'
import {getPublicationVariant} from '@shm/shared'
import {z} from 'zod'
import {grpcClient} from './app-grpc'
Expand Down
10 changes: 5 additions & 5 deletions frontend/apps/desktop/src/app-windows.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import appError from '@shm/app/errors'
import type {NavState} from '@shm/app/utils/navigation'
import {NavRoute, defaultRoute} from '@shm/app/utils/routes'
import type {AppWindowEvent} from '@shm/app/utils/window-events'
import {getRouteWindowType} from '@shm/app/utils/window-types'
import appError from '@shm/desktop/src/errors'
import type {NavState} from '@shm/desktop/src/utils/navigation'
import {NavRoute, defaultRoute} from '@shm/desktop/src/utils/routes'
import type {AppWindowEvent} from '@shm/desktop/src/utils/window-events'
import {getRouteWindowType} from '@shm/desktop/src/utils/window-types'
import {
BrowserView,
BrowserWindow,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "*.module.css";
Loading

0 comments on commit fcb0ba2

Please sign in to comment.