adhere better to GNU guidlines

This commit is contained in:
Florian Dold 2019-08-19 14:08:14 +02:00
parent 54fec75279
commit 10df69131f
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 91 additions and 10 deletions

2
.gitignore vendored
View File

@ -11,3 +11,5 @@ node_modules
yarn-error.log yarn-error.log
npm-packages-offline-cache/ npm-packages-offline-cache/
config.mk

View File

@ -9,6 +9,7 @@ ava = node_modules/ava/cli.js
nyc = node_modules/nyc/bin/nyc.js nyc = node_modules/nyc/bin/nyc.js
tslint = node_modules/tslint/bin/tslint tslint = node_modules/tslint/bin/tslint
-include config.mk
.PHONY: package-stable .PHONY: package-stable
package-stable: i18n package-stable: i18n
@ -40,7 +41,6 @@ typedoc:
.PHONY: clean .PHONY: clean
clean: clean:
rm -rf build/
rm -rf dist/ rm -rf dist/
.PHONY: check .PHONY: check
@ -70,3 +70,17 @@ i18n: yarn-install
done; done;
# generate .ts file containing all translations # generate .ts file containing all translations
$(gulp) po2js $(gulp) po2js
ifndef prefix
.PHONY: install
install:
@echo "no prefix configured, did you run ./configure?"
else
.PHONY: install
install:
@echo "installing to" $(prefix)
npm install -g --prefix $(prefix) .
endif

57
configure vendored
View File

@ -2,6 +2,63 @@
set -eu set -eu
prefix=/usr/local
usage() {
echo "Usage: ./configure [OPTION]"
echo
echo "Configuration:"
echo " -h, --help display this help and exit"
echo
echo "Installation directories:"
echo " --prefix=PREFIX install architecture-independent files in PREFIX [$prefix]"
}
# -allow a command to fail with !s side effect on errexit
# -use return value from ${PIPESTATUS[0]}, because ! hosed $?
! getopt --test > /dev/null
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
echo 'getopt not available'
exit 1
fi
LONGOPTS=prefix:,help
OPTIONS=h
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
# e.g. return value is 1
# then getopt has complained about wrong arguments to stdout
exit 2
fi
# read getopts output this way to handle the quoting right:
eval set -- "$PARSED"
while true; do
case "$1" in
--prefix)
prefix="$2"
shift 2
;;
-h|--help)
usage
exit 1
;;
--)
shift
break
;;
*)
echo "Programming error"
exit 3
;;
esac
done
echo "prefix=$prefix" >config.mk
node_version=$(node --version) node_version=$(node --version)
if [ ! "$?" -eq 0 ]; then if [ ! "$?" -eq 0 ]; then
echo 'Error: node executable not found.' echo 'Error: node executable not found.'

View File

@ -20,14 +20,12 @@
import { Wallet } from "../wallet"; import { Wallet } from "../wallet";
import { getDefaultNodeWallet } from "../headless/helpers"; import { getDefaultNodeWallet } from "../headless/helpers";
class AndroidWalletHelper { class AndroidWalletHelper {
wallet: Wallet | undefined; walletPromise: Promise<Wallet> | undefined;
constructor (private sendMessage: (m: any) => void) { constructor() {}
}
async init() { async init() {
this.wallet = await getDefaultNodeWallet(); this.walletPromise = getDefaultNodeWallet();
} }
} }
@ -35,19 +33,25 @@ export function installAndroidWalletListener() {
// @ts-ignore // @ts-ignore
const sendMessage: (m: any) => void = global.__akono_sendMessage; const sendMessage: (m: any) => void = global.__akono_sendMessage;
if (typeof sendMessage !== "function") { if (typeof sendMessage !== "function") {
const errMsg = "FATAL: cannot install android wallet listener: akono functions missing"; const errMsg =
"FATAL: cannot install android wallet listener: akono functions missing";
console.error(errMsg); console.error(errMsg);
throw new Error(errMsg); throw new Error(errMsg);
} }
const walletHelper = new AndroidWalletHelper(sendMessage); const walletHelper = new AndroidWalletHelper();
const onMessage = (msg: any) => { const onMessage = (msg: any) => {
const operation = msg.operation; const operation = msg.operation;
if (typeof operation !== "string") { if (typeof operation !== "string") {
console.error("message to android wallet helper must contain operation of type string"); console.error(
"message to android wallet helper must contain operation of type string",
);
return; return;
} }
const id = msg.id;
let result;
switch (operation) { switch (operation) {
case "init": case "init":
result = walletHelper.init();
break; break;
case "getBalances": case "getBalances":
break; break;
@ -57,7 +61,11 @@ export function installAndroidWalletListener() {
console.error(`operation "${operation}" not understood`); console.error(`operation "${operation}" not understood`);
return; return;
} }
const respMsg = { result, id };
console.log("sending message back", respMsg);
sendMessage(respMsg);
}; };
// @ts-ignore // @ts-ignore
globalThis.__akono_onMessage = onMessage; globalThis.__akono_onMessage = onMessage;
} }