From e5e7a608eef4deb10c33847e2d2a8019c228065c Mon Sep 17 00:00:00 2001 From: Snowflyt Date: Sat, 27 Jan 2024 21:14:33 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20Support=20macOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Bump version to v0.2.5 2. Update README --- README.md | 67 ++++++++++++++++++++++++++------------ README.zh-CN.md | 65 +++++++++++++++++++++++++----------- package.json | 2 +- src/components/Spinner.tsx | 1 + src/constants.ts | 2 +- src/footer.tsx | 21 ++++++++---- 6 files changed, 111 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index e75315c..570e46e 100644 --- a/README.md +++ b/README.md @@ -4,32 +4,33 @@ English | [简体中文](./README.zh-CN.md) ![Copilot suggestion screenshot](./docs/screenshot.png) -[GitHub Copilot](https://github.com/features/copilot) plugin for [Typora](https://typora.io/), provided through [Copilot.vim](https://github.com/github/copilot.vim). +[GitHub Copilot](https://github.com/features/copilot) plugin for [Typora](https://typora.io/) on both Windows, macOS and Linux, provided through [Copilot.vim](https://github.com/github/copilot.vim). This plugin uses the LSP server extracted from Copilot.vim to provide suggestions in real-time right from your editor. **⚠️ Warning:** This plugin is still in development and may not work properly. Please use it with caution. -_macOS is not supported yet. Besides, this plugin has not been fully tested on Linux, but it should work properly._ +_This plugin has not been fully tested on Linux, but it should work properly._ -## Compatiblility +## Compatibility _\*Note: `/` means not tested._ -**⚠️ Warning:** For users using Typora < 1.6, you need to install [Node.js](https://nodejs.org/en/download/) ≥ 18. +**⚠️ Warning:** For Windows / Linux users using Typora < 1.6 or macOS users using any version of Typora, you need to install [Node.js](https://nodejs.org/en/download/) ≥ 18. | Typora Version | Windows 11 | Ubuntu 22.04 | macOS 14.2 | | -------------- | ---------- | ------------ | ---------- | -| 1.7.6 | √ | / | × | -| 1.6.7 | √ | / | × | -| 1.6.4-dev | √ | / | × | -| 1.5.12 | √ | / | × | -| 1.4.8 | √ | / | × | -| 1.3.8 | √ | / | × | -| 1.2.5 | √ | / | × | -| 1.2.3 | √ | / | × | -| 1.0.3 | √ | / | × | -| 0.11.18-beta | √ | / | × | +| 1.8.5 | √ | / | √ | +| 1.7.6 | √ | / | / | +| 1.6.7 | √ | / | / | +| 1.6.4-dev | √ | / | / | +| 1.5.12 | √ | / | / | +| 1.4.8 | √ | / | / | +| 1.3.8 | √ | / | / | +| 1.2.5 | √ | / | / | +| 1.2.3 | √ | / | / | +| 1.0.3 | √ | / | / | +| 0.11.18-beta | √ | / | / | ## Prerequisites @@ -42,7 +43,9 @@ _\*Note: `/` means not tested._ For all platform users, first download the latest release from [the releases page](https://github.com/Snowfly-T/typora-copilot/releases) and unzip it. -Then for Windows users, locate to the folder where you unzipped the release and run the following command in PowerShell **as administrator**: +#### Windows + +For Windows users, locate to the folder where you unzipped the release and run the following command in PowerShell **as administrator**: ```powershell .\bin\install_windows.ps1 @@ -58,6 +61,26 @@ If the script fails to find Typora, you can specify the path to Typora manually: You’ll see a message logging the installation directory of the plugin. _Keep it in mind, you’ll need it when uninstalling the plugin._ After that, you can safely delete the release folder. +#### macOS + +For macOS users, locate to the folder where you unzipped the release and run the following command in terminal: + +```bash +sudo bash ./bin/install_macos.sh +``` + +If the script fails to find Typora, you can specify the path to Typora manually: + +```bash +sudo bash ./bin/install_macos.sh --path "/Applications/Typora.app/" # Replace with your Typora path +# Or use the alias +# sudo bash ./bin/install_macos.sh -p "/Applications/Typora.app/" # Replace with your Typora path +``` + +You’ll see a message logging the installation directory of the plugin. _Keep it in mind, you’ll need it when uninstalling the plugin._ After that, you can safely delete the release folder. + +#### Linux + For Linux users, locate to the folder where you unzipped the release and run the following command in terminal: ```bash @@ -76,8 +99,6 @@ You’ll see a message logging the installation directory of the plugin. _Keep i ### Manual Install -_The following instructions for macOS users are only left here for future reference. macOS is not supported yet._ - 1. Download the latest release from [the releases page](https://github.com/Snowfly-T/typora-copilot/releases) and unzip it. 2. For Windows / Linux users, find `window.html` in your Typora installation folder, usually located at `/resources/`; For macOS users, find `index.html` in your Typora installation folder, usually located at `/Contents/Resources/TypeMark/`. `` is the path where Typora is installed, replace it with your real Typora installation path (note that the angle brackets `<` and `>` should also be removed). This folder is called Typora resource folder in the following steps. 3. Create a folder named `copilot` in Typora resource folder. @@ -88,7 +109,7 @@ _The following instructions for macOS users are only left here for future refere ## Setup -When finished installation, you'll find an icon in the toolbar of Typora. Click it to open the panel of Copilot, and then click “Sign in to authenticate Copilot”. +When finished installation, you'll find an icon in the toolbar of Typora (i.e. the bottom-right corner of Typora). Click it to open the panel of Copilot, and then click “Sign in to authenticate Copilot”. ![Copilot icon](./docs/toolbar-icon.png) @@ -112,6 +133,14 @@ For Windows users, locate to the installation directory of the plugin and run th You can still specify the path to Typora manually by adding `-Path` or `-p`, just like the installation script. +For macOS users, locate to the installation directory of the plugin and run the following command in terminal. + +```bash +sudo bash ./bin/uninstall_macos.sh +``` + +You can still specify the path to Typora manually by adding `--path` or `-p`, just like the installation script. + For Linux users, locate to the installation directory of the plugin and run the following command in terminal. ```bash @@ -122,8 +151,6 @@ You can still specify the path to Typora manually by adding `--path` or `-p`, ju ### Manual Uninstall -_The following instructions for macOS users are only left here for future reference. macOS is not supported yet._ - 1. For Windows / Linux users, find `window.html` in your Typora installation folder, usually located at `/resources/`; For macOS users, find `index.html` in your Typora installation folder, usually located at `/Contents/Resources/TypeMark/`. `` is the path where Typora is installed, replace it with your real Typora installation path (note that the angle brackets `<` and `>` should also be removed). This folder is called Typora resource folder in the following steps. 2. Delete the `copilot` folder in Typora resource folder. 3. For Windows / Linux users, open the previous `window.html` file you found in Typora resource folder with a text editor, and delete ``; For macOS users, open the previous `index.html` file you found in Typora resource folder with a text editor, and delete ``. diff --git a/README.zh-CN.md b/README.zh-CN.md index 412b4ac..c33434d 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -4,32 +4,33 @@ ![Copilot 建议截图](./docs/screenshot.zh-CN.png) -[Typora](https://typora.io/) 的 [GitHub Copilot](https://github.com/features/copilot) 插件,由 [Copilot.vim](https://github.com/github/copilot.vim) 提供支持。 +[Typora](https://typora.io/) 的 [GitHub Copilot](https://github.com/features/copilot) 插件,支持 Windows、macOS 和 Linux,由 [Copilot.vim](https://github.com/github/copilot.vim) 提供支持。 该插件使用从 Copilot.vim 提取的 LSP 服务器,以在编辑器中实时提供建议。 **⚠️ 警告:** 该插件仍在开发中,可能无法正常工作。请谨慎使用。 -_暂不支持 macOS. 此外该插件在 Linux 上的使用尚未经过充分测试,但应该可以正常工作。_ +_该插件在 Linux 上的使用尚未经过充分测试,但应该可以正常工作。_ ## 兼容性 _\*注:`/` 表示未经过测试。_ -**⚠️ 警告:** 对于使用 Typora < 1.6 的用户,你需要安装 [Node.js](https://nodejs.org/en/download/) ≥ 18. +**⚠️ 警告:** 对于使用 Typora < 1.6 的 Windows / Linux 用户以及使用任何版本 Typora 的 macOS 用户,你需要安装 [Node.js](https://nodejs.org/en/download/) ≥ 18. | Typora Version | Windows 11 | Ubuntu 22.04 | macOS 14.2 | | -------------- | ---------- | ------------ | ---------- | -| 1.7.6 | √ | / | × | -| 1.6.7 | √ | / | × | -| 1.6.4-dev | √ | / | × | -| 1.5.12 | √ | / | × | -| 1.4.8 | √ | / | × | -| 1.3.8 | √ | / | × | -| 1.2.5 | √ | / | × | -| 1.2.3 | √ | / | × | -| 1.0.3 | √ | / | × | -| 0.11.18-beta | √ | / | × | +| 1.8.5 | √ | / | √ | +| 1.7.6 | √ | / | / | +| 1.6.7 | √ | / | / | +| 1.6.4-dev | √ | / | / | +| 1.5.12 | √ | / | / | +| 1.4.8 | √ | / | / | +| 1.3.8 | √ | / | / | +| 1.2.5 | √ | / | / | +| 1.2.3 | √ | / | / | +| 1.0.3 | √ | / | / | +| 0.11.18-beta | √ | / | / | ## 前置条件 @@ -42,7 +43,9 @@ _\*注:`/` 表示未经过测试。_ 对于所有平台的用户,首先从[发布页面](https://github.com/Snowfly-T/typora-copilot/releases)下载最新版本并解压。 -然后,对于 Windows 用户,定位到你解压的文件夹并在 PowerShell 中**以管理员身份**运行以下命令: +#### Windows + +对于 Windows 用户,定位到你解压的文件夹并在 PowerShell 中**以管理员身份**运行以下命令: ```powershell .\bin\install_windows.ps1 @@ -58,6 +61,26 @@ _\*注:`/` 表示未经过测试。_ 安装过程中,你会看到一条消息记录插件的安装目录。_记住它,在卸载插件时你会需要它。_ 安装完成后,你可以安全地删除刚才解压的文件夹。 +#### macOS + +对于 macOS 用户,定位到你解压的文件夹并在终端中运行以下命令: + +```bash +sudo bash ./bin/install_macos.sh +``` + +如果脚本无法找到 Typora,你可以手动指定 Typora 的路径: + +```bash +sudo bash ./bin/install_macos.sh --path "/Applications/Typora.app/" # 替换为你的 Typora 路径 +# 或使用别名 +# sudo bash ./bin/install_macos.sh -p "/Applications/Typora.app/" # 替换为你的 Typora 路径 +``` + +安装过程中,你会看到一条消息记录插件的安装目录。_记住它,在卸载插件时你会需要它。_ 安装完成后,你可以安全地删除刚才解压的文件夹。 + +#### Linux + 对于 Linux 用户,定位到你解压的文件夹并在终端中运行以下命令: ```bash @@ -76,8 +99,6 @@ sudo bash ./bin/install_linux.sh --path "/usr/share/typora/" # 替换为你的 T ### 手动安装 -_以下对 macOS 用户的说明仅供参考,本插件暂不支持 macOS._ - 1. 从[发布页面](https://github.com/Snowfly-T/typora-copilot/releases)下载最新版本并解压。 2. 找到 Typora 安装目录下的 `window.html` 文件,通常位于 `/resources/`;对于 macOS 用户,找到 Typora 安装目录下的 `index.html` 文件,通常位于 `/Contents/Resources/TypeMark/`。`` 是 Typora 的安装路径,替换为你的实际 Typora 安装路径(注意尖括号 `<` 和 `>` 也要删除)。这个文件夹在下面的步骤中被称为 Typora 资源文件夹。 3. 在 Typora 资源文件夹中创建一个名为 `copilot` 的文件夹。 @@ -88,7 +109,7 @@ _以下对 macOS 用户的说明仅供参考,本插件暂不支持 macOS._ ## 初始化 -完成安装后,你会在 Typora 工具栏中找到一个 Copilot 图标。点击它打开 Copilot 面板,然后点击“Sign in to authenticate Copilot”。 +完成安装后,你会在 Typora 工具栏(即界面底部右下角)找到一个 Copilot 图标。点击它打开 Copilot 面板,然后点击“Sign in to authenticate Copilot”。 ![Copilot 图标](./docs/toolbar-icon.zh-CN.png) @@ -112,6 +133,14 @@ _以下对 macOS 用户的说明仅供参考,本插件暂不支持 macOS._ 和安装时一样,如果脚本无法找到 Typora,你可以手动通过 `-Path` 或 `-p` 参数指定 Typora 的路径。 +对于 macOS 用户,定位到插件安装目录并在终端中运行以下命令: + +```bash +sudo bash ./bin/uninstall_macos.sh +``` + +和安装时一样,如果脚本无法找到 Typora,你可以手动通过 `--path` 或 `-p` 参数指定 Typora 的路径。 + 对于 Linux 用户,定位到插件安装目录并在终端中运行以下命令: ```bash @@ -122,8 +151,6 @@ sudo bash ./bin/uninstall_linux.sh ### 手动卸载 -_以下对 macOS 用户的说明仅供参考,本插件暂不支持 macOS._ - 1. 找到 Typora 安装目录下的 `window.html` 文件,通常位于 `/resources/`;对于 macOS 用户,找到 Typora 安装目录下的 `index.html` 文件,通常位于 `/Contents/Resources/TypeMark/`. `` 是 Typora 的安装路径,替换为你的实际 Typora 安装路径(注意尖括号 `<` 和 `>` 也要删除)。这个文件夹在下面的步骤中被称为 Typora 资源文件夹。 2. 删除 Typora 资源文件夹中的 `copilot` 文件夹。 3. 对于 Windows / Linux 用户,在 Typora 资源文件夹中用文本编辑器打开 `window.html`,删除 ``;对于 macOS 用户,在 Typora 资源文件夹中用文本编辑器打开 `index.html`,删除 ``. diff --git a/package.json b/package.json index 835ad72..5ea4885 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typora-copilot", - "version": "0.2.5-dev", + "version": "0.2.5", "private": true, "description": "GitHub Copilot plugin for Typora", "keywords": [ diff --git a/src/components/Spinner.tsx b/src/components/Spinner.tsx index 37bca7f..a4b4a00 100644 --- a/src/components/Spinner.tsx +++ b/src/components/Spinner.tsx @@ -11,6 +11,7 @@ const Spinner: FC = ({ color = "gray" }) => { diff --git a/src/constants.ts b/src/constants.ts index e812e13..b15e8d1 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -6,7 +6,7 @@ import { setGlobalVar } from "./utils/tools"; /** * Plugin version. */ -export const VERSION = "0.2.5-dev"; +export const VERSION = "0.2.5"; /** * Copilot plugin directory. diff --git a/src/footer.tsx b/src/footer.tsx index 5b4a6da..f7463ed 100644 --- a/src/footer.tsx +++ b/src/footer.tsx @@ -275,14 +275,23 @@ export const Footer: FC = ({ copilot }) => { * @returns A function that can be used to remove the footer element from the DOM. */ export const attachFooter = (copilot: CopilotClient) => { - const footerBar = getFooterBarDOM(); + const container = document.createElement("div"); - if (!footerBar) return () => {}; + const footerBar = getFooterBarDOM(); + if (footerBar) { + const firstFooterItemRight = $(footerBar).find(".footer-item-right")[0]; + if (firstFooterItemRight) firstFooterItemRight.insertAdjacentElement("beforebegin", container); + else footerBar.appendChild(container); + } else { + container.style.position = "fixed"; + container.style.bottom = "0"; + container.style.right = "0.25rem"; + container.style.zIndex = "1000"; + container.style.height = "2rem"; + container.style.width = "2.75rem"; + document.querySelector("content")!.appendChild(container); + } - const container = document.createElement("div"); - const firstFooterItemRight = $(footerBar).find(".footer-item-right")[0]; - if (firstFooterItemRight) firstFooterItemRight.insertAdjacentElement("beforebegin", container); - else footerBar.appendChild(container); const footer = ; render(footer, container);