Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion graphql-server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import resolvers from "./resolvers";
imports: [
GraphQLModule.forRoot<ApolloDriverConfig>({
autoSchemaFile:
process.env.NEXT_PUBLIC_FOR_ELECTRON === "true"
process.env.NEXT_PUBLIC_FOR_ELECTRON === "true" ||
process.env.NEXT_PUBLIC_FOR_TAURI === "true"
? process.env.SCHEMA_PATH
: "schema.gql",
context: ctx => ctx,
Expand Down
9 changes: 7 additions & 2 deletions graphql-server/src/fileStore/fileStore.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import path, { resolve } from "path";
import { DatabaseConnection } from "../databases/database.model";

const storePath =
process.env.NEXT_PUBLIC_FOR_ELECTRON === "true"
process.env.NEXT_PUBLIC_FOR_ELECTRON === "true" ||
process.env.NEXT_PUBLIC_FOR_TAURI === "true"
? path.join(process.env.NEXT_PUBLIC_USER_DATA_PATH ?? "", "store.json")
: resolve(__dirname, "../../store/store.json");

@Injectable()
export class FileStoreService {
getStore(): DatabaseConnection[] {
console.log("STORE PATH: ", storePath);
if (!fs.existsSync(storePath)) {
return [];
}
Expand Down Expand Up @@ -40,7 +42,10 @@ export class FileStoreService {
}

store.push(item);
if (process.env.NEXT_PUBLIC_FOR_ELECTRON === "true") {
if (
process.env.NEXT_PUBLIC_FOR_ELECTRON === "true" ||
process.env.NEXT_PUBLIC_FOR_TAURI === "true"
) {
if (!fs.existsSync(process.env.NEXT_PUBLIC_USER_DATA_PATH ?? "")) {
fs.mkdirSync(process.env.NEXT_PUBLIC_USER_DATA_PATH ?? "");
}
Expand Down
15 changes: 15 additions & 0 deletions web/build/renameTauriSidecar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import { execSync } from 'child_process';
import fs from 'fs';

const extension = process.platform === 'win32' ? '.exe' : '';

const rustInfo = execSync('rustc -vV');
const targetTriple = /host: (\S+)/g.exec(rustInfo)[1];
if (!targetTriple) {
console.error('Failed to determine platform target triple');
}
fs.renameSync(
`src-tauri/binaries/${process.argv[2]}${extension}`,
`src-tauri/binaries/${process.argv[2]}-${targetTriple}${extension}`
);
1 change: 1 addition & 0 deletions web/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default [
"main/preload.d.ts",
".next/**",
"build/**",
"src-tauri/**",
],
},
{
Expand Down
10 changes: 9 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"yalc": "yalc link",
"yalc:clean": "yalc remove --all",
"ci": "yarn prettier && yarn compile && yarn lint && yarn test && yarn build",
"clean": "tsc -b --clean && yarn yalc:clean"
"clean": "tsc -b --clean && yarn yalc:clean",
"package:tauri": "yarn --cwd ../graphql-server build && ncc build ../graphql-server/dist/main.js -o ../graphql-server/gql_dist && pkg ../graphql-server/gql_dist/index.js --output ./src-tauri/binaries/graphql-server && rm -rf ../graphql-server/gql_dist && cp build/mac/dolt src-tauri/binaries && node build/renameTauriSidecar.js dolt && node build/renameTauriSidecar.js graphql-server"
},
"dependencies": {
"@apollo/client": "^3.9.9",
Expand All @@ -42,6 +43,11 @@
"@dolthub/react-hooks": "^0.1.8",
"@dolthub/web-utils": "^0.1.9",
"@react-icons/all-files": "^4.1.0",
"@tauri-apps/api": "^2.8.0",
"@tauri-apps/plugin-fs": "~2",
"@tauri-apps/plugin-opener": "~2",
"@tauri-apps/plugin-shell": "^2.3.1",
"@vercel/ncc": "^0.38.4",
"ace-builds": "^1.37.5",
"apollo-upload-client": "^17.0.0",
"chance": "^1.1.11",
Expand Down Expand Up @@ -81,6 +87,7 @@
"@graphql-codegen/fragment-matcher": "^5.1.0",
"@graphql-codegen/typescript-operations": "^5.0.1",
"@graphql-codegen/typescript-react-apollo": "^4.0.0",
"@tauri-apps/cli": "^2.8.4",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.3.0",
Expand All @@ -101,6 +108,7 @@
"@types/url-parse": "^1",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.38.0",
"@yao-pkg/pkg": "^6.8.0",
"adm-zip": "^0.5.16",
"autoprefixer": "^10.4.21",
"babel-jest": "^29.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import Image from "next/legacy/image";
import { SyntheticEvent, useState } from "react";
import css from "./index.module.css";
import useAddConnection from "./useAddConnection";
import useTauri from "@hooks/useTauri";

const forElectron = process.env.NEXT_PUBLIC_FOR_ELECTRON === "true";
const forTauri = process.env.NEXT_PUBLIC_FOR_TAURI === "true";

type Props = {
conn: DatabaseConnectionFragment;
Expand All @@ -28,20 +30,31 @@ export default function Item({
const [startDoltServerError, setStartDoltServerError] = useState<
Error | undefined
>(undefined);
const { startDoltServer } = useTauri();
const type = getDatabaseType(conn.type ?? undefined, !!conn.isDolt);

const onSubmit = async (e: SyntheticEvent) => {
e.preventDefault();
const restartDoltServer =
forElectron && conn.isLocalDolt && !doltServerIsActive;
(forElectron || forTauri) && conn.isLocalDolt && !doltServerIsActive;

if (!restartDoltServer) {
await onAdd();
return;
}

try {
await window.ipc.invoke("start-dolt-server", conn.name, conn.port, false);
if (forElectron) {
await window.ipc.invoke(
"start-dolt-server",
conn.name,
conn.port,
false,
);
}
if (forTauri) {
await startDoltServer(conn.name, conn.port ?? "", false);
}
} catch (error) {
setStartDoltServerError(new Error(`${error}`));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useRouter } from "next/router";
import { useState } from "react";
import Item from "./Item";
import css from "./index.module.css";
import useTauri from "@hooks/useTauri";

type Props = {
connections: DatabaseConnectionFragment[];
Expand All @@ -21,6 +22,7 @@ export default function ExistingConnections(props: Props) {
const [deleteModalOpen, setDeleteModalOpen] = useState(false);
const [connectionNameToDelete, setConnectionNameToDelete] = useState("");
const [isLocalDolt, setIsLocalDolt] = useState(false);
const { removeDoltServer } = useTauri();
const onDeleteClicked = (name: string, local: boolean) => {
setConnectionNameToDelete(name);
setDeleteModalOpen(true);
Expand All @@ -29,7 +31,14 @@ export default function ExistingConnections(props: Props) {

const removeLocalDoltFolder = async () => {
try {
await window.ipc.invoke("remove-dolt-connection", connectionNameToDelete);
if (process.env.NEXT_PUBLIC_FOR_ELECTRON === "true") {
await window.ipc.invoke(
"remove-dolt-connection",
connectionNameToDelete,
);
} else if (process.env.NEXT_PUBLIC_FOR_TAURI === "true") {
await removeDoltServer(connectionNameToDelete);
}
} catch (error) {
console.error("Failed to remove local Dolt server:", error);
return new Error(`Failed to remove local Dolt server: ${error}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import StartDoltServerForm from "./StartDoltServerForm";
import { getStartLocalDoltServerDisabled } from "@pageComponents/ConnectionsPage/NewConnection/context/utils";

const forElectron = process.env.NEXT_PUBLIC_FOR_ELECTRON === "true";
const forTauri = process.env.NEXT_PUBLIC_FOR_TAURI === "true";

enum ConnectionOption {
Existing,
Expand Down Expand Up @@ -45,10 +46,11 @@ export default function About() {
state,
storedConnections,
);
const localDoltOptionsEnabled = forElectron || forTauri;

return (
<form onSubmit={onNext} className={css.form} data-cy="connection-tab-form">
{forElectron && (
{localDoltOptionsEnabled && (
<>
<Radio
checked={connectionOption === ConnectionOption.Existing}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import { ReactNode, SyntheticEvent, useEffect, useMemo, useState } from "react";
import { maybeDatabase } from "@lib/urls";
import { ConfigContextType, defaultState, getDefaultState } from "./state";
import { getConnectionUrl } from "./utils";
import useTauri from "@hooks/useTauri";

export const ConfigContext =
createCustomContext<ConfigContextType>("ConfigContext");

const forElectron = process.env.NEXT_PUBLIC_FOR_ELECTRON === "true";
const forTauri = process.env.NEXT_PUBLIC_FOR_TAURI === "true";

type Props = {
children: ReactNode;
Expand All @@ -38,6 +40,7 @@ export function ConfigProvider({ children }: Props) {
const [err, setErr] = useState<Error | undefined>(
res.err || connectionsRes.error,
);
const { startDoltServer, cloneDoltDatabase } = useTauri();

useEffectOnMount(() => {
const isDocker = window.location.origin === "http://localhost:3000";
Expand All @@ -55,7 +58,7 @@ export function ConfigProvider({ children }: Props) {
}, [res.err]);

useEffectOnMount(() => {
if (!forElectron) return;
if (!forElectron || !forTauri) return;
window.ipc.getDoltServerError(async (msg: string) => {
setErr(Error(msg));
});
Expand Down Expand Up @@ -100,17 +103,26 @@ export function ConfigProvider({ children }: Props) {
e.preventDefault();
setState({ loading: true });
try {
const result = await window.ipc.invoke(
"start-dolt-server",
state.name.trim(),
state.port,
!state.cloneDolt,
state.database,
);

if (result !== "success") {
setErr(Error(result));
return;
if (forElectron) {
const result = await window.ipc.invoke(
"start-dolt-server",
state.name.trim(),
state.port,
!state.cloneDolt,
state.database,
);

if (result !== "success") {
setErr(Error(result));
return;
}
} else if (forTauri) {
await startDoltServer(
state.name.trim(),
state.port,
!state.cloneDolt,
state.database,
);
}
await onSubmit(e);
} catch (error) {
Expand Down Expand Up @@ -138,14 +150,25 @@ export function ConfigProvider({ children }: Props) {
});
}, 10);

const result = await window.ipc.invoke(
"clone-dolthub-db",
owner.trim(),
remoteDbName.trim(),
newDbName.trim(),
state.name,
state.port,
);
let result;
if (forElectron) {
result = await window.ipc.invoke(
"clone-dolthub-db",
owner.trim(),
remoteDbName.trim(),
newDbName.trim(),
state.name,
state.port,
);
} else if (forTauri) {
result = await cloneDoltDatabase(
owner.trim(),
remoteDbName.trim(),
newDbName.trim(),
state.name,
state.port,
);
}

if (result !== "success") {
setErr(Error(result));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import DatabaseLayout from "@components/layouts/DatabaseLayout";
import { SqlEditorProvider } from "@contexts/sqleditor";
import useElectronMenu from "@hooks/useElectronMenu";
import useDesktopMenu from "@hooks/useDesktopMenu";
import { DatabasePageParams } from "@lib/params";
import { RefUrl } from "@lib/urls";
import { ReactNode } from "react";
Expand All @@ -22,7 +22,7 @@ type Props = {
};

export default function DatabasePage({ params, children, ...props }: Props) {
useElectronMenu(params);
useDesktopMenu(params);

return (
<SqlEditorProvider params={params}>
Expand Down
Loading
Loading