Skip to content

Commit

Permalink
Merge pull request #603 from BlueBubblesApp/zach/fix/ngrok-config
Browse files Browse the repository at this point in the history
v1.9.4
  • Loading branch information
zlshames authored Jan 10, 2024
2 parents 5fa5691 + 0e41eef commit 4a36b7d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bluebubbles-server",
"version": "1.9.3",
"version": "1.9.4",
"description": "BlueBubbles Server is the app that powers the BlueBubbles app ecosystem",
"private": true,
"workspaces": [
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bluebubbles/server",
"version": "1.9.3",
"version": "1.9.4",
"main": "./dist/main.js",
"license": "Apache-2.0",
"author": {
Expand Down
5 changes: 0 additions & 5 deletions packages/server/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,11 +1001,6 @@ class BlueBubblesServer extends EventEmitter {
await this.restartProxyServices();
}

// If the ngrok region is different, restart the ngrok process
if (prevConfig.ngrok_region !== nextConfig.ngrok_region && !proxiesRestarted) {
await this.restartProxyServices();
}

// Install the bundle if the Private API is turned on
if (
prevConfig.enable_private_api !== nextConfig.enable_private_api ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { isEmpty, safeTrim } from "@server/helpers/utils";
import path from "path";
import fs from "fs";
import { Server } from "@server";
import { connect, disconnect, kill, authtoken, Ngrok } from "ngrok";
import { connect, disconnect, kill, authtoken, Ngrok, upgradeConfig } from "ngrok";
import { Proxy } from "../proxy";
import { app } from "electron";
import { userHomeDir } from "@server/fileSystem";

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

await this.migrateConfigFile();

const opts: Ngrok.Options = {
port: Server().repo.getConfig("socket_port") ?? 1234,
region: (Server().repo.getConfig("ngrok_region") as Ngrok.Region) ?? "us",
binPath: (bPath: string) => bPath.replace("app.asar", "app.asar.unpacked"),
onStatusChange: async (status: string) => {
Server().log(`Ngrok status: ${status}`);
Expand Down Expand Up @@ -88,6 +93,38 @@ export class NgrokService extends Proxy {
return connect(opts);
}

async migrateConfigFile(): Promise<void> {
const newConfig = path.join(app.getPath("userData"), 'ngrok', 'ngrok.yml');
const oldConfig = path.join(userHomeDir(), '.ngrok2', '/ngrok.yml');

// If the new config file already exists, don't do anything
if (fs.existsSync(newConfig)) return;

// If the old config file doesn't exist, don't do anything
if (!fs.existsSync(oldConfig)) return;

// If the old config file exists and is empty, we can delete it
// so that it's recreated in the proper location
const contents = fs.readFileSync(oldConfig).toString('utf-8');
if (!contents || isEmpty(contents.trim())) {
Server().log('Detected old & empty Ngrok config file. Removing file...', 'debug');
fs.unlinkSync(oldConfig);
return;
}

// Upgrade the old config if the new config doesn't exist
// and the old config is not empty.
try {
Server().log('Ngrok config file needs upgrading. Upgrading...', 'debug');
await upgradeConfig({
relocate: true,
binPath: (bPath: string) => bPath.replace("app.asar", "app.asar.unpacked")
});
} catch (ex) {
Server().log('An error occurred while upgrading the Ngrok config file!', 'debug');
}
}

/**
* Disconnect from ngrok
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bluebubbles/ui",
"version": "1.9.3",
"version": "1.9.4",
"homepage": "./",
"license": "Apache-2.0",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
} from '@chakra-ui/react';
import { AiOutlineInfoCircle } from 'react-icons/ai';
import { useAppSelector } from '../../../hooks';
import { NgrokRegionField } from '../../../components/fields/NgrokRegionField';
import { NgrokAuthTokenField } from '../../../components/fields/NgrokAuthTokenField';
import { ProxySetupField } from '../../../components/fields/ProxySetupField';
import { ServerPasswordField } from '../../../components/fields/ServerPasswordField';
Expand Down Expand Up @@ -59,8 +58,6 @@ export const ConnectionSettings = (): JSX.Element => {
<Spacer />
<ProxySetupField />
<Spacer />
{(proxyService === 'ngrok') ? (<NgrokRegionField />) : null}
<Spacer />
{(proxyService === 'ngrok') ? (<NgrokAuthTokenField />) : null}
<Spacer />
<Divider orientation='horizontal' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { ProxySetupField } from '../../../components/fields/ProxySetupField';
import { useAppSelector } from '../../../hooks';
import { NgrokAuthTokenField } from '../../../components/fields/NgrokAuthTokenField';
import { NgrokRegionField } from '../../../components/fields/NgrokRegionField';
import { ServerPasswordField } from '../../../components/fields/ServerPasswordField';

export const ConnectionWalkthrough = (): JSX.Element => {
Expand Down Expand Up @@ -48,7 +47,6 @@ export const ConnectionWalkthrough = (): JSX.Element => {
{(proxyService === 'ngrok') ? (
<>
<NgrokAuthTokenField />
<NgrokRegionField />
</>
): null}
</Stack>
Expand Down

0 comments on commit 4a36b7d

Please sign in to comment.