From ba16abb9f3b4eb6aaca2db8123893b75ac72659c Mon Sep 17 00:00:00 2001
From: Sayamame-beans <61457993+Sayamame-beans@users.noreply.github.com>
Date: Fri, 18 Aug 2023 19:36:05 +0900
Subject: [PATCH] =?UTF-8?q?fix(frontend):=20Misskey=E3=83=97=E3=83=A9?=
 =?UTF-8?q?=E3=82=B0=E3=82=A4=E3=83=B3=E3=82=92=E3=82=A4=E3=83=B3=E3=82=B9?=
 =?UTF-8?q?=E3=83=88=E3=83=BC=E3=83=AB=E3=81=99=E3=82=8B=E9=9A=9B=E3=81=AE?=
 =?UTF-8?q?AiScript=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7=E3=83=B3=E3=81=AE?=
 =?UTF-8?q?=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF=E3=81=8C0.14.0=E4=BB=A5?=
 =?UTF-8?q?=E9=99=8D=E3=81=AB=E5=AF=BE=E5=BF=9C=E3=81=97=E3=81=A6=E3=81=84?=
 =?UTF-8?q?=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?=
 =?UTF-8?q?=20(#11729)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* fix: aiscript version check of plugin

* Update CHANGELOG.md

* docs(CHANGELOG): remove 11420 issue link

* fix(frontend): Possibility of exception in non-semver version format
---
 CHANGELOG.md                                          |  1 +
 .../frontend/src/pages/settings/plugin.install.vue    | 11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5c3d73f68..5d9301d74 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,7 @@
 - Fix: iOSで画面を回転させるとテキストサイズが変わる問題を修正
 - Fix: word mute for sub note is not applied
 - Fix: タイムラインを下にスクロールしてノート画面に移動して再び戻ったら以前のスクロール位置を失う問題を修正
+- Fix: Misskeyプラグインをインストールする際のAiScriptバージョンのチェックが0.14.0以降に対応していない問題を修正
 
 ### Server
 - cacheRemoteFilesの初期値はfalseになりました
diff --git a/packages/frontend/src/pages/settings/plugin.install.vue b/packages/frontend/src/pages/settings/plugin.install.vue
index dd070dcb1..d848f8e21 100644
--- a/packages/frontend/src/pages/settings/plugin.install.vue
+++ b/packages/frontend/src/pages/settings/plugin.install.vue
@@ -19,6 +19,7 @@ SPDX-License-Identifier: AGPL-3.0-only
 
 <script lang="ts" setup>
 import { defineAsyncComponent, nextTick, ref } from 'vue';
+import { compareVersions } from 'compare-versions';
 import { Interpreter, Parser, utils } from '@syuilo/aiscript';
 import { v4 as uuid } from 'uuid';
 import MkTextarea from '@/components/MkTextarea.vue';
@@ -44,6 +45,14 @@ function installPlugin({ id, meta, src, token }) {
 	}));
 }
 
+function isSupportedAiScriptVersion(version: string): boolean {
+	try {
+		return (compareVersions(version, '0.12.0') >= 0);
+	} catch (err) {
+		return false;
+	}
+}
+
 async function install() {
 	if (code.value == null) return;
 
@@ -54,7 +63,7 @@ async function install() {
 			text: 'No language version annotation found :(',
 		});
 		return;
-	} else if (!(lv.startsWith('0.12.') || lv.startsWith('0.13.'))) {
+	} else if (!isSupportedAiScriptVersion(lv)) {
 		os.alert({
 			type: 'error',
 			text: `aiscript version '${lv}' is not supported :(`,