Skip to content

Commit

Permalink
update outline_proxy_controller path
Browse files Browse the repository at this point in the history
  • Loading branch information
jyyi1 committed Apr 24, 2024
1 parent 58757aa commit 5bb961c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
17 changes: 15 additions & 2 deletions client/infrastructure/electron/app_paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,22 @@ export function getAppPath() {
return electronAppPath;
}

export function pathToEmbeddedBinary(filename: string) {
export function pathToEmbeddedTun2socksBinary() {
return path.join(
unpackedAppPath(), 'client', 'output', 'build',
(isWindows ? 'windows' : 'linux'),
filename + (isWindows ? '.exe' : ''));
'tun2socks' + (isWindows ? '.exe' : ''));
}

/**
* Get the parent directory path containing the background service binaries.
* On Windows, this folder contains `OutlineService.exe`.
* While on Linux this folder contains `outline_proxy_controller`.
* @returns A string representing the path of the directory that contains service binaries.
*/
export function pathToEmbeddedOutlineService() {
if (isWindows) {
return getAppPath();
}
return path.join(unpackedAppPath(), 'client', 'tools', 'outline_proxy_controller', 'dist');
}
4 changes: 2 additions & 2 deletions src/electron/electron-builder.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files": ["build/electron", "client/www", "client/resources/tray", "!node_modules/electron"],
"asarUnpack": ["client", "tools"],
"asarUnpack": ["client"],
"artifactName": "Outline-Client.${ext}",
"directories": {
"output": "output/build/dist"
Expand All @@ -10,7 +10,7 @@
"target": "AppImage",
"arch": ["x64"]
},
"files": ["build/icons/png", "client/output/build/linux", "tools/outline_proxy_controller/dist"],
"files": ["build/icons/png", "client/output/build/linux", "client/tools/outline_proxy_controller/dist"],
"icon": "build/icons/png",
"category": "Network"
},
Expand Down
6 changes: 3 additions & 3 deletions src/electron/go_vpn_tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {powerMonitor} from 'electron';
import {ChildProcessHelper, ProcessTerminatedExitCodeError, ProcessTerminatedSignalError} from './process';
import {RoutingDaemon} from './routing_service';
import {VpnTunnel} from './vpn_tunnel';
import {pathToEmbeddedBinary} from '../../client/infrastructure/electron/app_paths';
import {pathToEmbeddedTun2socksBinary} from '../../client/infrastructure/electron/app_paths';
import {ShadowsocksSessionConfig} from '../../client/src/www/app/tunnel';
import {TunnelStatus} from '../../client/src/www/app/tunnel';
import {ErrorCode, fromErrorCode, UnexpectedPluginError} from '../../client/src/www/model/errors';
Expand Down Expand Up @@ -222,7 +222,7 @@ class GoTun2socks {
private readonly process: ChildProcessHelper;

constructor(private readonly config: ShadowsocksSessionConfig) {
this.process = new ChildProcessHelper(pathToEmbeddedBinary('tun2socks'));
this.process = new ChildProcessHelper(pathToEmbeddedTun2socksBinary());
}

async start(isUdpEnabled: boolean): Promise<void> {
Expand Down Expand Up @@ -259,7 +259,7 @@ class GoTun2socks {
if (data?.toString().includes('tun2socks running')) {
console.debug('tun2socks started');
autoRestart = true;
this.process.onStdErr = null;
this.process.onStdErr = undefined;
}
};
try {
Expand Down
13 changes: 6 additions & 7 deletions src/electron/routing_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as path from 'path';
import * as fsextra from 'fs-extra';
import * as sudo from 'sudo-prompt';

import {getAppPath} from '../../client/infrastructure/electron/app_paths';
import {pathToEmbeddedOutlineService} from '../../client/infrastructure/electron/app_paths';
import {TunnelStatus} from '../../client/src/www/app/tunnel';
import {ErrorCode, SystemConfigurationException} from '../../client/src/www/model/errors';

Expand Down Expand Up @@ -67,7 +67,7 @@ enum RoutingServiceStatusCode {
// - Linux: systemctl start|stop outline_proxy_controller.service
// - Windows: net start|stop OutlineService
export class RoutingDaemon {
private socket: Socket | undefined;
private socket: Socket | null | undefined;

private stopping = false;

Expand Down Expand Up @@ -182,7 +182,7 @@ export class RoutingDaemon {

private async writeReset() {
return new Promise<void>((resolve, reject) => {
const written = this.socket.write(
const written = this.socket?.write(
JSON.stringify({action: RoutingServiceAction.RESET_ROUTING, parameters: {}} as RoutingServiceRequest),
err => {
if (err) {
Expand Down Expand Up @@ -262,12 +262,11 @@ function installWindowsRoutingServices(): Promise<void> {
// build/windows
//
// Surrounding quotes important, consider "c:\program files"!
const script = `"${path.join(getAppPath(), WINDOWS_INSTALLER_FILENAME)}"`;
const script = `"${path.join(pathToEmbeddedOutlineService(), WINDOWS_INSTALLER_FILENAME)}"`;
return executeCommandAsRoot(script);
}

async function installLinuxRoutingServices(): Promise<void> {
const OUTLINE_PROXY_CONTROLLER_PATH = path.join('tools', 'outline_proxy_controller', 'dist');
const LINUX_INSTALLER_FILENAME = 'install_linux_service.sh';
const installationFileDescriptors: Array<{filename: string; executable: boolean; sha256: string}> = [
{filename: LINUX_INSTALLER_FILENAME, executable: true, sha256: ''},
Expand All @@ -276,7 +275,7 @@ async function installLinuxRoutingServices(): Promise<void> {
];

// These Linux service files are located in a mounted folder of the AppImage, typically
// located at /tmp/.mount_Outlinxxxxxx/resources/. These files can only be acceeded by
// located at /tmp/.mount_Outlinxxxxxx/resources/. These files can only be accessed by
// the user who launched Outline.AppImage, so even root cannot access the files or folders.
// Therefore we have to copy these files to a normal temporary folder, and execute them
// as root.
Expand All @@ -290,7 +289,7 @@ async function installLinuxRoutingServices(): Promise<void> {
// - https://github.com/AppImage/AppImageKit/issues/146
// - https://xwartz.gitbooks.io/electron-gitbook/content/en/tutorial/application-packaging.html
const tmp = await fsextra.mkdtemp('/tmp/');
const srcFolderPath = path.join(getAppPath(), OUTLINE_PROXY_CONTROLLER_PATH);
const srcFolderPath = pathToEmbeddedOutlineService();

console.log(`copying service installation files to ${tmp}`);
for (const descriptor of installationFileDescriptors) {
Expand Down

0 comments on commit 5bb961c

Please sign in to comment.