Skip to content

Commit d53267b

Browse files
authored
Merge pull request #513 from dolthub/taylor/merge-fix
web: Fix nextron build, some conflicts improvements
2 parents 8518f74 + 09bd5c3 commit d53267b

File tree

19 files changed

+105
-75
lines changed

19 files changed

+105
-75
lines changed

web/eslint.config.js renamed to web/eslint.config.mjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export default [
2222
"build/**",
2323
"node_modules/**",
2424
"*.config.js",
25+
"*.config.mjs",
26+
"renderer/*.config.js",
27+
"renderer/*.config.mjs",
28+
"main/preload.d.ts",
29+
".next/**",
30+
"build/**",
2531
],
2632
},
2733
{
@@ -96,7 +102,7 @@ export default [
96102
rules: {
97103
// ESLint base rules
98104
...js.configs.recommended.rules,
99-
105+
100106
// TypeScript rules
101107
"@typescript-eslint/array-type": ["error", { default: "array-simple" }],
102108
"@typescript-eslint/await-thenable": "error",
@@ -218,4 +224,4 @@ export default [
218224
},
219225
},
220226
prettierConfig,
221-
];
227+
];

web/jest.setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "@testing-library/jest-dom";
22
import { setConfig } from "next/config";
3-
import config from "./renderer/next.config.js";
3+
import config from "./renderer/next.config.mjs";
44

55
// Make sure you can use "publicRuntimeConfig" within tests.
66
setConfig({

web/main/background.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import path from "path";
1+
import { ChildProcess } from "child_process";
22
import {
33
app,
44
BrowserWindow,
5+
crashReporter,
56
ipcMain,
7+
IpcMainEvent,
68
Menu,
79
shell,
10+
systemPreferences,
811
utilityProcess,
912
UtilityProcess,
10-
IpcMainEvent,
11-
systemPreferences,
12-
crashReporter,
1313
} from "electron";
1414
import serve from "electron-serve";
15-
import { initMenu } from "./helpers/menu";
16-
import { startServer } from "./doltServer";
17-
import { ChildProcess } from "child_process";
15+
import path from "path";
16+
import { cloneAndStartDatabase } from "./doltClone";
1817
import { doltLogin } from "./doltLogin";
18+
import { startServer } from "./doltServer";
19+
import { createWindow } from "./helpers/createWindow";
20+
import { initMenu } from "./helpers/menu";
1921
import {
2022
getErrorMessage,
2123
removeDoltServerFolder,
2224
} from "./helpers/removeDoltServerFolder";
23-
import { cloneAndStartDatabase } from "./doltClone";
24-
import { createWindow } from "./helpers/createWindow";
2525

2626
const isProd = process.env.NODE_ENV === "production";
2727
const userDataPath = app.getPath("userData");
@@ -30,6 +30,8 @@ const schemaPath = isProd
3030
: "../graphql-server/schema.gql";
3131
process.env.SCHEMA_PATH = schemaPath;
3232
process.env.NEXT_PUBLIC_FOR_ELECTRON = "true";
33+
process.env.NEXT_PUBLIC_FOR_MAC_NAV =
34+
process.platform === "darwin" ? "true" : "false";
3335
process.env.NEXT_PUBLIC_USER_DATA_PATH = userDataPath;
3436

3537
const HEADER_HEIGHT = 48;
@@ -66,7 +68,7 @@ function isExternalUrl(url: string) {
6668
return !url.includes("localhost:") && !url.includes("app://");
6769
}
6870

69-
function createGraphqlSeverProcess() {
71+
async function createGraphqlSeverProcess() {
7072
const serverPath =
7173
process.env.NODE_ENV === "production"
7274
? path.join(
@@ -79,17 +81,17 @@ function createGraphqlSeverProcess() {
7981
: path.join("../graphql-server", "dist", "main.js");
8082
graphqlServerProcess = utilityProcess.fork(serverPath, [], { stdio: "pipe" });
8183

82-
graphqlServerProcess?.stdout?.on("data", (chunk: Buffer) => {
84+
graphqlServerProcess.stdout?.on("data", async (chunk: Buffer) => {
8385
console.log("server data", chunk.toString("utf8"));
8486
// Send the Server console.log messages to the main browser window
85-
mainWindow?.webContents.executeJavaScript(`
87+
await mainWindow.webContents.executeJavaScript(`
8688
console.info('Server Log:', ${JSON.stringify(chunk.toString("utf8"))})`);
8789
});
8890

89-
graphqlServerProcess?.stderr?.on("data", (chunk: Buffer) => {
91+
graphqlServerProcess.stderr?.on("data", async (chunk: Buffer) => {
9092
console.error("server error", chunk.toString("utf8"));
9193
// Send the Server console.error messages out to the main browser window
92-
mainWindow?.webContents.executeJavaScript(`
94+
await mainWindow.webContents.executeJavaScript(`
9395
console.error('Server Log:', ${JSON.stringify(chunk.toString("utf8"))})`);
9496
});
9597
}
@@ -168,7 +170,7 @@ app.on("ready", async () => {
168170

169171
Menu.setApplicationMenu(initMenu(mainWindow, isProd));
170172
setupTitleBarClickMac();
171-
createGraphqlSeverProcess();
173+
await createGraphqlSeverProcess();
172174

173175
await waitForGraphQLServer("http://localhost:9002/graphql");
174176

@@ -183,7 +185,9 @@ app.on("ready", async () => {
183185
// always deny, optionally redirect to browser
184186
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
185187
if (isExternalUrl(url)) {
186-
shell.openExternal(url);
188+
shell
189+
.openExternal(url)
190+
.catch(err => console.error("Failed to open URL:", err));
187191
}
188192

189193
return { action: "deny" };
@@ -192,9 +196,9 @@ app.on("ready", async () => {
192196

193197
// hit when clicking <a href/> with no target
194198
// optionally redirect to browser
195-
mainWindow.webContents.on("will-navigate", (event, url) => {
199+
mainWindow.webContents.on("will-navigate", async (event, url) => {
196200
if (isExternalUrl(url)) {
197-
shell.openExternal(url);
201+
await shell.openExternal(url);
198202
event.preventDefault();
199203
}
200204
});

web/main/doltClone.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import path from "path";
2-
import { BrowserWindow } from "electron";
31
import { ChildProcess, execFile } from "child_process";
2+
import { BrowserWindow } from "electron";
3+
import path from "path";
4+
import { startServerProcess } from "./doltServer";
45
import {
56
createFolder,
67
getDatabasesPath,
78
getDoltPaths,
89
} from "./helpers/filePath";
9-
import { startServerProcess } from "./doltServer";
1010

1111
export async function cloneAndStartDatabase(
1212
owner: string,
@@ -41,7 +41,7 @@ export async function cloneAndStartDatabase(
4141
}
4242
}
4343

44-
function cloneDatabase(
44+
async function cloneDatabase(
4545
owner: string,
4646
remoteDatabase: string,
4747
newDbName: string,

web/main/doltLogin.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ export async function doltLogin(
2020

2121
let timedOut = false;
2222
const timeoutDuration = 1 * 60 * 1000; // 1 minutes
23+
let child: ChildProcess | undefined;
2324

2425
let timeoutId = setTimeout(() => {
2526
timedOut = true;
26-
if (child) {
27-
child.kill(); // Terminate the process
28-
}
27+
child?.kill(); // Terminate the process
2928
activeProcesses.delete(requestId);
3029
mainWindow.webContents.send(
3130
"server-error",
@@ -34,7 +33,7 @@ export async function doltLogin(
3433
reject(new Error("Login timed out"));
3534
}, timeoutDuration);
3635

37-
const child = execFile(
36+
child = execFile(
3837
doltPath,
3938
["login"],
4039
{ cwd: dbFolderPath, maxBuffer: 1024 * 1024 * 10 },

web/main/doltServer.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import path from "path";
2-
import { BrowserWindow } from "electron";
31
import { ChildProcess, execFile, spawn } from "child_process";
2+
import { BrowserWindow } from "electron";
43
import fs from "fs";
4+
import path from "path";
55
import {
66
createFolder,
77
getDatabasesPath,
@@ -43,7 +43,7 @@ export async function startServer(
4343
}
4444

4545
//initialize the Dolt repository by running `dolt init` in dbFolderPath
46-
function initializeDoltRepository(
46+
async function initializeDoltRepository(
4747
doltPath: string,
4848
dbFolderPath: string,
4949
mainWindow: BrowserWindow,
@@ -56,7 +56,7 @@ function initializeDoltRepository(
5656
{ cwd: dbFolderPath },
5757
async (error, stdout, stderr) => {
5858
if (error) {
59-
const initErr = `Error initializing Dolt: ${error}`;
59+
const initErr = `Error initializing Dolt: ${error.message}`;
6060
mainWindow.webContents.send("server-error", initErr);
6161

6262
reject(new Error(initErr));
@@ -89,7 +89,7 @@ function initializeDoltRepository(
8989
});
9090
}
9191

92-
export function startServerProcess(
92+
export async function startServerProcess(
9393
doltPath: string,
9494
dbFolderPath: string,
9595
port: string,
@@ -103,7 +103,9 @@ export function startServerProcess(
103103
fs.mkdirSync(path.dirname(socketPath), { recursive: true });
104104
try {
105105
fs.unlinkSync(socketPath);
106-
} catch {}
106+
} catch {
107+
// Ignore error if the socket does not exist
108+
}
107109
argsArray = ["sql-server", "-P", port, "--socket", socketPath];
108110
}
109111

@@ -119,7 +121,7 @@ export function startServerProcess(
119121
reject(err);
120122
});
121123

122-
doltServerProcess.stdout?.on("data", async data => {
124+
doltServerProcess.stdout.on("data", async data => {
123125
const logMsg = data.toString();
124126
console.log("dolt server process log", logMsg);
125127
if (
@@ -139,7 +141,7 @@ export function startServerProcess(
139141
}
140142
});
141143

142-
doltServerProcess.stderr?.on("data", async data => {
144+
doltServerProcess.stderr.on("data", async data => {
143145
const errorMsg = data.toString();
144146
console.log("dolt server process stderr", errorMsg);
145147
// Check if the message is a warning or an error

web/main/helpers/createWindow.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
2-
screen,
32
BrowserWindow,
43
BrowserWindowConstructorOptions,
54
Rectangle,
5+
screen,
66
} from "electron";
77
import Store from "electron-store";
88

@@ -20,6 +20,7 @@ export const createWindow = (
2020
y: options.y ?? 0,
2121
};
2222
let state = {};
23+
let win: BrowserWindow;
2324

2425
const restore = () => store.get(key, defaultSize);
2526

@@ -34,14 +35,11 @@ export const createWindow = (
3435
};
3536
};
3637

37-
const windowWithinBounds = (windowState: Rectangle, bounds: Rectangle) => {
38-
return (
39-
windowState.x >= bounds.x &&
40-
windowState.y >= bounds.y &&
41-
windowState.x + windowState.width <= bounds.x + bounds.width &&
42-
windowState.y + windowState.height <= bounds.y + bounds.height
43-
);
44-
};
38+
const windowWithinBounds = (windowState: Rectangle, bounds: Rectangle) =>
39+
windowState.x >= bounds.x &&
40+
windowState.y >= bounds.y &&
41+
windowState.x + windowState.width <= bounds.x + bounds.width &&
42+
windowState.y + windowState.height <= bounds.y + bounds.height;
4543

4644
const resetToDefaults = () => {
4745
const bounds = screen.getPrimaryDisplay().bounds;
@@ -52,9 +50,9 @@ export const createWindow = (
5250
};
5351

5452
const ensureVisibleOnSomeDisplay = (windowState: Rectangle) => {
55-
const visible = screen.getAllDisplays().some(display => {
56-
return windowWithinBounds(windowState, display.bounds);
57-
});
53+
const visible = screen
54+
.getAllDisplays()
55+
.some(display => windowWithinBounds(windowState, display.bounds));
5856
if (!visible) {
5957
// Window is partially or fully not visible now.
6058
// Reset it to safe defaults.
@@ -71,7 +69,7 @@ export const createWindow = (
7169
};
7270

7371
state = ensureVisibleOnSomeDisplay(restore());
74-
const win = new BrowserWindow({
72+
win = new BrowserWindow({
7573
...state,
7674
...options,
7775
webPreferences: {

web/main/helpers/menu.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { workbenchGithubRepo } from "@lib/constants";
22
import {
3-
shell,
43
BrowserWindow,
54
Menu,
65
MenuItemConstructorOptions,
76
app,
7+
shell,
88
} from "electron";
99

1010
export function initMenu(
@@ -173,14 +173,14 @@ export function initMenu(
173173
submenu: [
174174
{
175175
label: "Documentation",
176-
click() {
177-
shell.openExternal("https://docs.dolthub.com/");
176+
async click() {
177+
await shell.openExternal("https://docs.dolthub.com/");
178178
},
179179
},
180180
{
181181
label: "View on GitHub",
182-
click() {
183-
shell.openExternal(workbenchGithubRepo);
182+
async click() {
183+
await shell.openExternal(workbenchGithubRepo);
184184
},
185185
},
186186
],

web/main/preload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { contextBridge, ipcRenderer } from "electron";
22

33
const handler = {
4-
invoke(channel: string, ...args: unknown[]) {
4+
async invoke(channel: string, ...args: unknown[]) {
55
return ipcRenderer.invoke(channel, ...args);
66
},
77
onMenuClicked: (callback: (value: string) => {}) =>
@@ -35,7 +35,7 @@ const handler = {
3535
ipcRenderer.send("remove-dolt-connection", connectionName),
3636
getDoltServerError: (callback: (value: string) => {}) =>
3737
ipcRenderer.on("server-error", (_event, value) => callback(value)),
38-
doltLogin: (connectionName: string) =>
38+
doltLogin: async (connectionName: string) =>
3939
ipcRenderer.invoke("dolt-login", connectionName),
4040
cancelDoltLogin: (requestId: string) =>
4141
ipcRenderer.send("cancel-dolt-login", requestId),

web/nextron.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ process.env.NEXT_PUBLIC_FOR_MAC_NAV =
55
module.exports = {
66
mainSrcDir: "main",
77
rendererSrcDir: "renderer",
8-
webpack: (config, env) => config,
8+
webpack: config => config,
99
};

0 commit comments

Comments
 (0)