Skip to content

Commit

Permalink
✨ feat: Support macOS
Browse files Browse the repository at this point in the history
1. Bump version to v0.2.5
2. Update README
  • Loading branch information
Snowflyt committed Jan 27, 2024
1 parent 486a54d commit e5e7a60
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 47 deletions.
67 changes: 47 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 `<typora_root_path>/resources/`; For macOS users, find `index.html` in your Typora installation folder, usually located at `<typora_root_path>/Contents/Resources/TypeMark/`. `<typora_root_path>` 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.
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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 `<typora_root_path>/resources/`; For macOS users, find `index.html` in your Typora installation folder, usually located at `<typora_root_path>/Contents/Resources/TypeMark/`. `<typora_root_path>` 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 `<script src="./copilot/index.js" defer="defer"></script>`; For macOS users, open the previous `index.html` file you found in Typora resource folder with a text editor, and delete `<script src="./copilot/index.js" defer></script>`.
Expand Down
65 changes: 46 additions & 19 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 || / | / |

## 前置条件

Expand All @@ -42,7 +43,9 @@ _\*注:`/` 表示未经过测试。_

对于所有平台的用户,首先从[发布页面](https://github.com/Snowfly-T/typora-copilot/releases)下载最新版本并解压。

然后,对于 Windows 用户,定位到你解压的文件夹并在 PowerShell 中**以管理员身份**运行以下命令:
#### Windows

对于 Windows 用户,定位到你解压的文件夹并在 PowerShell 中**以管理员身份**运行以下命令:

```powershell
.\bin\install_windows.ps1
Expand All @@ -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
Expand All @@ -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` 文件,通常位于 `<typora_root_path>/resources/`;对于 macOS 用户,找到 Typora 安装目录下的 `index.html` 文件,通常位于 `<typora_root_path>/Contents/Resources/TypeMark/``<typora_root_path>` 是 Typora 的安装路径,替换为你的实际 Typora 安装路径(注意尖括号 `<``>` 也要删除)。这个文件夹在下面的步骤中被称为 Typora 资源文件夹。
3. 在 Typora 资源文件夹中创建一个名为 `copilot` 的文件夹。
Expand All @@ -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)

Expand All @@ -112,6 +133,14 @@ _以下对 macOS 用户的说明仅供参考,本插件暂不支持 macOS._

和安装时一样,如果脚本无法找到 Typora,你可以手动通过 `-Path``-p` 参数指定 Typora 的路径。

对于 macOS 用户,定位到插件安装目录并在终端中运行以下命令:

```bash
sudo bash ./bin/uninstall_macos.sh
```

和安装时一样,如果脚本无法找到 Typora,你可以手动通过 `--path``-p` 参数指定 Typora 的路径。

对于 Linux 用户,定位到插件安装目录并在终端中运行以下命令:

```bash
Expand All @@ -122,8 +151,6 @@ sudo bash ./bin/uninstall_linux.sh

### 手动卸载

_以下对 macOS 用户的说明仅供参考,本插件暂不支持 macOS._

1. 找到 Typora 安装目录下的 `window.html` 文件,通常位于 `<typora_root_path>/resources/`;对于 macOS 用户,找到 Typora 安装目录下的 `index.html` 文件,通常位于 `<typora_root_path>/Contents/Resources/TypeMark/`. `<typora_root_path>` 是 Typora 的安装路径,替换为你的实际 Typora 安装路径(注意尖括号 `<``>` 也要删除)。这个文件夹在下面的步骤中被称为 Typora 资源文件夹。
2. 删除 Typora 资源文件夹中的 `copilot` 文件夹。
3. 对于 Windows / Linux 用户,在 Typora 资源文件夹中用文本编辑器打开 `window.html`,删除 `<script src="./copilot/index.js" defer="defer"></script>`;对于 macOS 用户,在 Typora 资源文件夹中用文本编辑器打开 `index.html`,删除 `<script src="./copilot/index.js" defer></script>`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
1 change: 1 addition & 0 deletions src/components/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const Spinner: FC<SpinnerProps> = ({ color = "gray" }) => {
<svg
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
style={{ height: "100%", width: "100%" }}
dangerouslySetInnerHTML={{
__html: /* html */ `
<style>
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 15 additions & 6 deletions src/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,23 @@ export const Footer: FC<FooterOptions> = ({ 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 = <Footer copilot={copilot} />;
render(footer, container);

Expand Down

0 comments on commit e5e7a60

Please sign in to comment.