Chrome拡張機能があり、NativeHost jsonファイルによって開始された端末プロセスが開きます。このjsonファイルをシステムにインストールするには、OSxのNativeMessagHostフォルダにコピーする必要があります.Windowsでは、ローカルユーザのレジストリをいくつか変更します。 サンプル拡張コードでは、このようなもののインストールは.bat/.shスクリプトを使用して行われますが、ターミナルを開き、これらのスクリプトを実行することは悪夢になる可能性があるため、ユーザーフレンドリーではありません。 これらのNativeHost.jsonをユーザーフレンドリーな方法でインストールする方法はありますか? NativeHost.jsonためChrome拡張機能用NativeHostをインストール
ソースコードは(クローム拡張サンプルコードから撮影)することができます。
{
"name": "com.google.chrome.example.echo",
"description": "Chrome Native Messaging API Example Host",
"path": "HOST_PATH",
"type": "stdio",
"allowed_origins": [
"chrome-extension://<ID>"
]
}
と.SHは、次のようになります。
set -e
DIR="$(cd "$(dirname "$0")" && pwd)"
if [ "$(uname -s)" == "Darwin" ]; then
if [ "$(whoami)" == "root" ]; then
TARGET_DIR="/Library/Google/Chrome/NativeMessagingHosts"
else
TARGET_DIR="$HOME/Library/Application Support/Google/Chrome/NativeMessagingHosts"
fi
else
if [ "$(whoami)" == "root" ]; then
TARGET_DIR="/etc/opt/chrome/native-messaging-hosts"
else
TARGET_DIR="$HOME/.config/google-chrome/NativeMessagingHosts"
fi
fi
HOST_NAME=com.google.chrome.example.echo
# Create directory to store native messaging host.
mkdir -p "$TARGET_DIR"
# Copy native messaging host manifest.
cp "$DIR/$HOST_NAME.json" "$TARGET_DIR"
# Update host path in the manifest.
HOST_PATH=/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal
ESCAPED_HOST_PATH=${HOST_PATH////\\/}
sed -i -e "s/HOST_PATH/$ESCAPED_HOST_PATH/" "$TARGET_DIR/$HOST_NAME.json"
# Set permissions for the manifest so that all users can read it.
chmod o+r "$TARGET_DIR/$HOST_NAME.json"
echo "Native messaging host $HOST_NAME has been installed."