Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

feat: add right click helper on unix like system. #361

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,37 @@
[![](https://img.shields.io/github/stars/zimocode/smartup)](https://github.com/zimocode/smartup/stargazers)
[![](https://img.shields.io/github/license/zimocode/smartup)](LICENSE)

[English](README.md) ·[简体中文](README-zh_CN.md)
[English](README.md) ·[简体中文](README-zh_CN.md)

## 安装右键助手
自行编译`rightClickHelper`目录下的go文件或者下载预编译文件。
赋予可执行权限后,先在终端测试能否正常运行,如正常运行应该会有如下输出

```shell
❯ ./darwin_arm64
{"version": "0.7"}[debug] sent msg: {"version": "0.7"}
```

如果有类似下列输出,则表明依赖库不存在,需要自行安装依赖库后再编译。
```shell
❯ ./darwin_amd64
dyld[60020]: Library not loaded: '/usr/local/opt/libpng/lib/libpng16.16.dylib'
Referenced from: '~/smartup/rightClickHelper/darwin_amd64'
Reason: tried: '/usr/local/opt/libpng/lib/libpng16.16.dylib' (no such file), '/usr/local/lib/libpng16.16.dylib' (no such file), '/usr/lib/libpng16.16.dylib' (no such file)
[1] 60020 abort ./darwin_amd64
```
编译命令如下:
```shell
# On Ubuntu dependency of robotgo: libx11-dev xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxtst-dev libpng++-dev
(cd rightClickHelper && go mod tidy && go build -ldflags "-s -w" -o rightClickHelper rightClickHelper.go)
```

编译成功后,按`GOOS_GOARCH`格式(如`linux_arm64`)重命名后,替换或补充在`rightClickHelper`目录下,执行`installRightClickHelper.sh`安装。

### macOS第一次点击右键时,会有授权弹窗提示

![授权弹窗提示](rightClickHelper/permission1.jpg)

### 按图授权后,重启浏览器即可。

![按图授权](rightClickHelper/permission2.jpg)
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ smartUP Gestures has ben uploaded to these browser's extension store, you'll ins
| Edge | [https://microsoftedge.microsoft.com/addons/detail/elponhbfjjjihgeijofonnflefhcbckp](https://microsoftedge.microsoft.com/addons/detail/elponhbfjjjihgeijofonnflefhcbckp) |
| Firefox | [https://addons.mozilla.org/firefox/addon/smartup/](https://addons.mozilla.org/firefox/addon/smartup/) |

### Build right click helper
```shell
# On Ubuntu dependency of robotgo: libx11-dev xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxtst-dev libpng++-dev
(cd rightClickHelper && go mod tidy && go build -ldflags "-s -w" -o rightClickHelper rightClickHelper.go)
```

## License

[![License](https://img.shields.io/github/license/zimocode/smartup?logo=github&logoColor=white)](LICENSE)
[![License](https://img.shields.io/github/license/zimocode/smartup?logo=github&logoColor=white)](LICENSE)
68 changes: 68 additions & 0 deletions installRightClickHelper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/sh
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

set -e

HOST_BIN=""
DIR="$( cd "$( dirname "$0" )" && pwd )"
if [ "$(uname -s)" = "Darwin" ]; then
SED="/usr/bin/sed -i ''"
[ "$(/usr/bin/uname -m)" = "arm64" ] && HOST_BIN="$DIR/rightClickHelper/darwin_arm64" || HOST_BIN="$DIR/rightClickHelper/darwin_amd64"
if [ "$(whoami)" = "root" ]; then
# Edge use TARGET_DIR="/Library/Microsoft/Edge/NativeMessagingHosts"
# Chromium use TARGET_DIR="/Library/Chromium/NativeMessagingHosts"
TARGET_DIR="/Library/Google/Chrome/NativeMessagingHosts"
else
# Edge use TARGET_DIR="$HOME/Library/Application Support/Microsoft/Edge/NativeMessagingHosts"
# Chromium use TARGET_DIR="$HOME/Library/Application Support/Chromium/NativeMessagingHosts"
TARGET_DIR="$HOME/Library/Application Support/Google/Chrome/NativeMessagingHosts"
fi
else
SED="/usr/bin/sed -i"
[ "$(/usr/bin/uname -m)" = "x86_64" ] && HOST_BIN="$DIR/rightClickHelper/linux_amd64" || HOST_BIN="$DIR/rightClickHelper/linux_arm64"
if [ "$(whoami)" = "root" ]; then
# Edge find it out yourself
# Chromium use TARGET_DIR="/etc/chromium/native-messaging-hosts"
TARGET_DIR="/etc/opt/chrome/native-messaging-hosts"
else
# Edge find it out yourself
# Chromium use TARGET_DIR="$HOME/.config/chromium/NativeMessagingHosts"
TARGET_DIR="$HOME/.config/google-chrome/NativeMessagingHosts"
fi
fi

HOST_NAME=com.smartup.rightclickhelper

# Create directory to store native messaging host.
mkdir -p "$TARGET_DIR"

# create native messaging host manifest.
cat << EOF > "/tmp/$HOST_NAME.json"
{
"name": "com.smartup.rightclickhelper",
"description": "Right Click Helper for SmartUp",
"path": "HOST_PATH",
"type": "stdio",
"allowed_origins": [
"chrome-extension://okhdcmknlkpjecjobpijmniikbieejln/",
"chrome-extension://bgjfekefhjemchdeigphccilhncnjldn/",
"chrome-extension://jbfidehpoofganklkddfkcjeeaabimmb/"
]
}
EOF

# Update host path in the manifest.
HOST_PATH="$TARGET_DIR/smartUpRightClickHelper"
ESCAPED_HOST_PATH=${HOST_PATH////\\/}

$SED "s/HOST_PATH/$ESCAPED_HOST_PATH/" "/tmp/$HOST_NAME.json"

mv "/tmp/$HOST_NAME.json" "$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"

[ -f "$HOST_BIN" ] && cp "$HOST_BIN" "$HOST_PATH" && chmod +x "$HOST_PATH" \
&& echo "Native messaging host $HOST_NAME has been installed to $HOST_PATH." \
|| echo "No binary found for $HOST_BIN, please build it yourself."
Loading