Skip to content

Commit

Permalink
now really fix it for android
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-Laux committed May 16, 2024
1 parent 208ea85 commit 7dc82d0
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions deltachat-rpc-server/npm-package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import {
import package_json from "./package.json" with { type: "json" };
import { createRequire } from "node:module";

// exports
// - [ ] a raw starter that has a stdin/out handle thingie like desktop uses
// - [X] a function that already wraps the stdio handle from above into the deltachat jsonrpc bindings

function findRPCServerInNodeModules() {
const arch = os.arch();
const operating_system = process.platform;
Expand All @@ -43,6 +39,32 @@ function findRPCServerInNodeModules() {
}
}

/**
* @returns {Promise<string>}
*/
async function getLocationInPath() {
const exec = promisify(execFile);

if (os.platform() === "win32") {
const { stdout: executable } = await exec("where", [PATH_EXECUTABLE_NAME], {
shell: true,
});
return executable;
}

try {
const { stdout: executable } = await exec(
"command",
["-v", PATH_EXECUTABLE_NAME],
{ shell: true }
);
return executable;
} catch (error) {
if (error.code == 127) return "";
else throw error
}
}

/** @type {import("./index").FnTypes.getRPCServerPath} */
export async function getRPCServerPath(
options = { skipSearchInPath: false, disableEnvPath: false }
Expand All @@ -65,12 +87,7 @@ export async function getRPCServerPath(

// 2. check if it can be found in PATH
if (!process.env[SKIP_SEARCH_IN_PATH] && !skipSearchInPath) {
const exec = promisify(execFile);

const { stdout: executable } =
os.platform() !== "win32"
? await exec("command", ["-v", PATH_EXECUTABLE_NAME], { shell: true })
: await exec("where", [PATH_EXECUTABLE_NAME], { shell: true });
const executable = await getLocationInPath();

// by just trying to execute it and then use "command -v deltachat-rpc-server" (unix) or "where deltachat-rpc-server" (windows) to get the path to the executable
if (executable.length > 1) {
Expand Down

0 comments on commit 7dc82d0

Please sign in to comment.