Skip to content

Commit 4a36b7d

Browse files
authored
Merge pull request #603 from BlueBubblesApp/zach/fix/ngrok-config
v1.9.4
2 parents 5fa5691 + 0e41eef commit 4a36b7d

File tree

7 files changed

+42
-15
lines changed

7 files changed

+42
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bluebubbles-server",
3-
"version": "1.9.3",
3+
"version": "1.9.4",
44
"description": "BlueBubbles Server is the app that powers the BlueBubbles app ecosystem",
55
"private": true,
66
"workspaces": [

packages/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bluebubbles/server",
3-
"version": "1.9.3",
3+
"version": "1.9.4",
44
"main": "./dist/main.js",
55
"license": "Apache-2.0",
66
"author": {

packages/server/src/server/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,11 +1001,6 @@ class BlueBubblesServer extends EventEmitter {
10011001
await this.restartProxyServices();
10021002
}
10031003

1004-
// If the ngrok region is different, restart the ngrok process
1005-
if (prevConfig.ngrok_region !== nextConfig.ngrok_region && !proxiesRestarted) {
1006-
await this.restartProxyServices();
1007-
}
1008-
10091004
// Install the bundle if the Private API is turned on
10101005
if (
10111006
prevConfig.enable_private_api !== nextConfig.enable_private_api ||

packages/server/src/server/services/proxyServices/ngrokService/index.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { isEmpty, safeTrim } from "@server/helpers/utils";
2+
import path from "path";
3+
import fs from "fs";
24
import { Server } from "@server";
3-
import { connect, disconnect, kill, authtoken, Ngrok } from "ngrok";
5+
import { connect, disconnect, kill, authtoken, Ngrok, upgradeConfig } from "ngrok";
46
import { Proxy } from "../proxy";
7+
import { app } from "electron";
8+
import { userHomeDir } from "@server/fileSystem";
59

610
// const sevenHours = 1000 * 60 * 60 * 7; // This is the old ngrok timeout
711
const oneHour45 = 1000 * 60 * (60 + 45); // This is the new ngrok timeout
@@ -28,9 +32,10 @@ export class NgrokService extends Proxy {
2832
throw new Error('You must provide an Auth Token to use the Ngrok Proxy Service!');
2933
}
3034

35+
await this.migrateConfigFile();
36+
3137
const opts: Ngrok.Options = {
3238
port: Server().repo.getConfig("socket_port") ?? 1234,
33-
region: (Server().repo.getConfig("ngrok_region") as Ngrok.Region) ?? "us",
3439
binPath: (bPath: string) => bPath.replace("app.asar", "app.asar.unpacked"),
3540
onStatusChange: async (status: string) => {
3641
Server().log(`Ngrok status: ${status}`);
@@ -88,6 +93,38 @@ export class NgrokService extends Proxy {
8893
return connect(opts);
8994
}
9095

96+
async migrateConfigFile(): Promise<void> {
97+
const newConfig = path.join(app.getPath("userData"), 'ngrok', 'ngrok.yml');
98+
const oldConfig = path.join(userHomeDir(), '.ngrok2', '/ngrok.yml');
99+
100+
// If the new config file already exists, don't do anything
101+
if (fs.existsSync(newConfig)) return;
102+
103+
// If the old config file doesn't exist, don't do anything
104+
if (!fs.existsSync(oldConfig)) return;
105+
106+
// If the old config file exists and is empty, we can delete it
107+
// so that it's recreated in the proper location
108+
const contents = fs.readFileSync(oldConfig).toString('utf-8');
109+
if (!contents || isEmpty(contents.trim())) {
110+
Server().log('Detected old & empty Ngrok config file. Removing file...', 'debug');
111+
fs.unlinkSync(oldConfig);
112+
return;
113+
}
114+
115+
// Upgrade the old config if the new config doesn't exist
116+
// and the old config is not empty.
117+
try {
118+
Server().log('Ngrok config file needs upgrading. Upgrading...', 'debug');
119+
await upgradeConfig({
120+
relocate: true,
121+
binPath: (bPath: string) => bPath.replace("app.asar", "app.asar.unpacked")
122+
});
123+
} catch (ex) {
124+
Server().log('An error occurred while upgrading the Ngrok config file!', 'debug');
125+
}
126+
}
127+
91128
/**
92129
* Disconnect from ngrok
93130
*/

packages/ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bluebubbles/ui",
3-
"version": "1.9.3",
3+
"version": "1.9.4",
44
"homepage": "./",
55
"license": "Apache-2.0",
66
"scripts": {

packages/ui/src/app/layouts/settings/connection/ConnectionSettings.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
} from '@chakra-ui/react';
2222
import { AiOutlineInfoCircle } from 'react-icons/ai';
2323
import { useAppSelector } from '../../../hooks';
24-
import { NgrokRegionField } from '../../../components/fields/NgrokRegionField';
2524
import { NgrokAuthTokenField } from '../../../components/fields/NgrokAuthTokenField';
2625
import { ProxySetupField } from '../../../components/fields/ProxySetupField';
2726
import { ServerPasswordField } from '../../../components/fields/ServerPasswordField';
@@ -59,8 +58,6 @@ export const ConnectionSettings = (): JSX.Element => {
5958
<Spacer />
6059
<ProxySetupField />
6160
<Spacer />
62-
{(proxyService === 'ngrok') ? (<NgrokRegionField />) : null}
63-
<Spacer />
6461
{(proxyService === 'ngrok') ? (<NgrokAuthTokenField />) : null}
6562
<Spacer />
6663
<Divider orientation='horizontal' />

packages/ui/src/app/layouts/walkthrough/connection/ConnectionWalkthrough.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
import { ProxySetupField } from '../../../components/fields/ProxySetupField';
1111
import { useAppSelector } from '../../../hooks';
1212
import { NgrokAuthTokenField } from '../../../components/fields/NgrokAuthTokenField';
13-
import { NgrokRegionField } from '../../../components/fields/NgrokRegionField';
1413
import { ServerPasswordField } from '../../../components/fields/ServerPasswordField';
1514

1615
export const ConnectionWalkthrough = (): JSX.Element => {
@@ -48,7 +47,6 @@ export const ConnectionWalkthrough = (): JSX.Element => {
4847
{(proxyService === 'ngrok') ? (
4948
<>
5049
<NgrokAuthTokenField />
51-
<NgrokRegionField />
5250
</>
5351
): null}
5452
</Stack>

0 commit comments

Comments
 (0)