feat: add desktop2

This commit is contained in:
reya 2024-02-05 14:18:27 +07:00
parent 08fa7de01d
commit a21da11a91
16 changed files with 3107 additions and 230 deletions

6
apps/desktop2/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
node_modules
/.cache
/build
/public/build
.env

37
apps/desktop2/README.md Normal file
View File

@ -0,0 +1,37 @@
# templates/spa
This template leverages [Remix SPA Mode](https://remix.run/docs/en/main/future/spa-mode) to build your app as a Single-Page Application using [Client Data](https://remix.run/docs/en/main/guides/client-data) for all of you data loads and mutations.
⚠️ This is built on top of the Remix Vite template. Remix support for Vite is currently unstable and not recommended for production.
📖 See the [Remix Vite docs][remix-vite-docs] for details on supported features.
## Setup
```shellscript
npx create-remix@latest --template remix-run/remix/templates/spa
```
## Development
You can develop your SPA app just like you would a normal Remix app, via:
```shellscript
npm run dev
```
## Production
When you are ready yo build a production version of your app, `npm run build` will generate your assets and an `index.html` for the SPA.
```shellscript
npm run build
```
You can serve this from any server of your choosing, for a simple example, you could use [http-server](https://www.npmjs.com/package/http-server):
```shellscript
npx http-server build/client/
```
[remix-vite-docs]: https://remix.run/docs/en/main/future/vite

View File

@ -0,0 +1,12 @@
import { RemixBrowser } from "@remix-run/react";
import { startTransition, StrictMode } from "react";
import { hydrateRoot } from "react-dom/client";
startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
</StrictMode>
);
});

View File

@ -0,0 +1,21 @@
import type { EntryContext } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import { renderToString } from "react-dom/server";
export default function handleRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext
) {
let html = renderToString(
<RemixServer context={remixContext} url={request.url} />
);
if (html.startsWith("<html")) {
html = "<!DOCTYPE html>\n" + html;
}
return new Response(html, {
headers: { "Content-Type": "text/html" },
status: responseStatusCode,
});
}

View File

@ -0,0 +1,42 @@
import {
Links,
Meta,
Outlet,
Scripts,
ScrollRestoration,
} from "@remix-run/react";
export default function App() {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body>
<Outlet />
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}
export function HydrateFallback() {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body>
<p>Loading...</p>
<Scripts />
</body>
</html>
);
}

View File

@ -0,0 +1,32 @@
import type { MetaFunction } from "@remix-run/node";
export const meta: MetaFunction = () => {
return [
{ title: "New Remix SPA" },
{ name: "description", content: "Welcome to Remix (SPA Mode)!" },
];
};
export default function Index() {
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
<h1>Welcome to Remix (SPA Mode)</h1>
<ul>
<li>
<a
target="_blank"
href="https://remix.run/future/spa-mode"
rel="noreferrer"
>
SPA Mode Guide
</a>
</li>
<li>
<a target="_blank" href="https://remix.run/docs" rel="noreferrer">
Remix Docs
</a>
</li>
</ul>
</div>
);
}

2
apps/desktop2/env.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
/// <reference types="@remix-run/node" />
/// <reference types="vite/client" />

View File

@ -0,0 +1,30 @@
{
"name": "@lume/desktop2",
"private": true,
"sideEffects": false,
"type": "module",
"scripts": {
"build": "remix vite:build",
"dev": "remix vite:dev",
"start": "http-server build/client/",
"typecheck": "tsc"
},
"dependencies": {
"@remix-run/node": "^2.6.0",
"@remix-run/react": "^2.6.0",
"http-server": "^14.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@remix-run/dev": "^2.6.0",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"typescript": "^5.1.6",
"vite": "^5.0.0",
"vite-tsconfig-paths": "^4.2.1"
},
"engines": {
"node": ">=18.0.0"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -0,0 +1,24 @@
{
"include": ["env.d.ts", "**/*.ts", "**/*.tsx"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"target": "ES2022",
"strict": true,
"allowJs": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},
// Remix takes care of building everything in `remix build`.
"noEmit": true
}
}

View File

@ -0,0 +1,10 @@
import { unstable_vitePlugin as remix } from "@remix-run/dev";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
export default defineConfig({
plugins: [
remix({ unstable_ssr: false, buildDirectory: "../../dist" }),
tsconfigPaths(),
],
});

View File

@ -3,8 +3,10 @@
"private": true,
"version": "3.0.1",
"scripts": {
"build": "turbo build",
"dev": "turbo dev",
"build": "turbo run build",
"dev": "turbo run dev",
"web:dev": "turbo run dev --filter web",
"desktop:dev": "turbo run dev --filter desktop2",
"tauri": "tauri"
},
"devDependencies": {
@ -29,7 +31,6 @@
"@tauri-apps/plugin-shell": "^2.0.0-beta.0",
"@tauri-apps/plugin-sql": "^2.0.0-beta.0",
"@tauri-apps/plugin-updater": "^2.0.0-beta.0",
"@tauri-apps/plugin-upload": "^2.0.0-beta.0",
"million": "^3.0.2"
"@tauri-apps/plugin-upload": "^2.0.0-beta.0"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -25,17 +25,7 @@ fn main() {
tauri::Builder::default()
.setup(|app| {
let handle = app.handle().clone();
let config_dir = app.path().app_config_dir().unwrap();
let db = DATABASE_BUILDER
.create(config_dir.join("app.db"))
.expect("failed to create app database");
// run db migrate
let rw = db
.rw_transaction()
.expect("failed to create rw migration transaction");
rw.migrate::<Account>().expect("failed to migrate Account");
rw.commit().expect("failed to commit migration");
let config_dir = handle.path().app_config_dir().unwrap();
tauri::async_runtime::spawn(async move {
// Create database connection
@ -46,6 +36,18 @@ fn main() {
// Create nostr connection
let client = ClientBuilder::default().database(nostr_db).build();
// create app database connection
let db = DATABASE_BUILDER
.create(config_dir.join("app.db"))
.expect("failed to create app database");
// run db migrate
let rw = db
.rw_transaction()
.expect("failed to create rw migration transaction");
rw.migrate::<Account>().expect("failed to migrate Account");
rw.commit().expect("failed to commit migration");
// get stored account
let r = db.r_transaction().expect("failed to create ro transaction");
let accounts: Vec<Account> = r

View File

@ -5,8 +5,8 @@
"identifier": "nu.lume.Lume",
"build": {
"beforeBuildCommand": "pnpm run build",
"beforeDevCommand": "pnpm run dev",
"devUrl": "http://localhost:3000",
"beforeDevCommand": "pnpm desktop:dev",
"devUrl": "http://localhost:5173",
"frontendDist": "../dist"
},
"app": {

View File

@ -1,12 +1,15 @@
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"outputs": ["dist/**"]
},
"dev": {
"cache": true
},
"type-check": {}
}
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"outputs": [
"dist/**"
]
},
"dev": {
"cache": false,
"persistent": true
},
"type-check": {}
}
}