Skip to content

Commit

Permalink
Merge pull request #7 from X-CASH-official/macos-2-0-1-cli-support
Browse files Browse the repository at this point in the history
Support 2.0.1 xcash core for MacOS and fix issues related to cli binaries download
  • Loading branch information
denniselite committed Mar 31, 2021
2 parents 286a07f + 46d5cc3 commit c0ef50d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21,698 deletions.
33 changes: 17 additions & 16 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ function createWindow() {
}

// Constants
const BINARIES_LINUX_DIR_NAME = "xcash-cli-linux-2.0.0"
const BINARIES_MAC_OS_DIR_NAME = "xcash-cli-osx-2.0.0"
const BINARIES_WINDOWS_DIR_NAME = "xcash-cli-windows-2.0.0"
const BINARIES_LINUX_DIR_NAME = "xcash-cli-linux-2.0.1"
const BINARIES_MAC_OS_DIR_NAME = "xcash-cli-osx-2.0.1"
const BINARIES_WINDOWS_DIR_NAME = "xcash-cli-windows-2.0.1"

const DATABASE = '{"wallet_data": [],"contact_data": [],"wallet_settings": {"autolock": 10,"remote_node": "us1.xcash.foundation:18281"}}';
const DIR = process.platform !== "win32" ? `${process.env.HOME}/xcash-official/` : (`${process.env.USERPROFILE}\\xcash-official\\`).replace(/\\/g,"\\\\");
Expand All @@ -27,7 +27,7 @@ function createWindow() {
const WALLET_RPC_LOG = `${DIR}xcash-wallet-rpc.log`;

const downloadBinaries = async (url: string): Promise<void> => {
const pathToSave = path.resolve(__dirname, 'downloads', 'xcash-2.0.zip')
const pathToSave = path.resolve(`${DIR}downloads`, 'xcash-2.0.zip')

const response = await axios({
method: 'GET',
Expand All @@ -47,7 +47,7 @@ function createWindow() {

const prepareWorkingDir = async (): Promise<void> => {
fs.mkdirSync(DIR);
fs.mkdirSync("./downloads");
fs.mkdirSync(`${DIR}downloads`);

let binariesDir: string
switch (process.platform) {
Expand All @@ -62,28 +62,29 @@ function createWindow() {
break;
}

await downloadBinaries(`https://github.com/X-CASH-official/xcash-core/releases/download/2.0.0/${binariesDir}.zip`);
await downloadBinaries(`https://github.com/X-CASH-official/xcash-core/releases/download/2.0.1/${binariesDir}.zip`);

const zip = new AdmZip(`${__dirname}/downloads/xcash-2.0.zip`);
zip.extractAllTo(`${__dirname}/downloads`, true);
const zip = new AdmZip(`${DIR}downloads/xcash-2.0.zip`);
zip.extractAllTo(`${DIR}downloads`, true);

switch (process.platform) {
case "darwin":
exec(`chmod -R 755 ./downloads`);
fs.copyFileSync(`${__dirname}/downloads/${binariesDir}/xcash-wallet-rpc`, `${DIR}xcash-wallet-rpc`);
exec(`chmod +x ${DIR}/xcash-wallet-rpc`)
exec(`chmod -R 755 ${DIR}downloads`);
fs.copyFileSync(`${DIR}downloads/bin/xcash-wallet-rpc`, `${DIR}xcash-wallet-rpc`);
exec(`chmod -R 755 ${DIR}`);
exec(`chmod +x ${DIR}xcash-wallet-rpc`);
break;
case "win32":
fs.copyFileSync(`./downloads/${binariesDir}/xcash-wallet-rpc.exe`, `${DIR}xcash-wallet-rpc.exe`)
fs.copyFileSync(`${DIR}downloads/bin/xcash-wallet-rpc.exe`, `${DIR}xcash-wallet-rpc.exe`);
break;
default:
exec(`chmod -R 755 ./downloads`);
fs.copyFileSync(`${__dirname}/downloads/xcash-wallet-rpc`, `${DIR}xcash-wallet-rpc`);
exec(`chmod +x ${DIR}/xcash-wallet-rpc`)
exec(`chmod -R 755 ${DIR}downloads`);
fs.copyFileSync(`${DIR}downloads/bin/xcash-wallet-rpc`, `${DIR}xcash-wallet-rpc`);
exec(`chmod +x ${DIR}xcash-wallet-rpc`);
break;
}

fs.rmdirSync("./downloads", { recursive: true });
fs.rmdirSync(`${DIR}downloads`, { recursive: true });
}

// create the directory if it does not exist, and download and copy the xcash-wallet-rpc binary to it
Expand Down
Loading

0 comments on commit c0ef50d

Please sign in to comment.