diff --git a/app/src/mobile/menu/index.ts b/app/src/mobile/menu/index.ts index 3fc4ddf3f..3d8c09c4f 100644 --- a/app/src/mobile/menu/index.ts +++ b/app/src/mobile/menu/index.ts @@ -16,7 +16,7 @@ import {initAbout} from "../settings/about"; import {getRecentDocs} from "./getRecentDocs"; import {initEditor} from "../settings/editor"; import {App} from "../../index"; -import {isHuawei, isInAndroid, isInIOS, isIPhone} from "../../protyle/util/compatibility"; +import {isDisabledFeature, isHuawei, isInAndroid, isInIOS, isIPhone} from "../../protyle/util/compatibility"; import {newFile} from "../../util/newFile"; import {afterLoadPlugin} from "../../plugin/loader"; import {commandPanel} from "../../boot/globalEvent/command/panel"; @@ -45,8 +45,9 @@ export const initRightMenu = (app: App) => { let aiHTML = ``; - if (isHuawei()) { + if (isHuawei() || isDisabledFeature("ai")) { // Access to the OpenAI API is no longer supported on Huawei devices https://github.com/siyuan-note/siyuan/issues/8192 + // Apps in Chinese mainland app stores no longer provide AI access settings https://github.com/siyuan-note/siyuan/issues/13051 aiHTML = ""; } diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts index c3f4bdae8..597b43dc9 100644 --- a/app/src/protyle/util/compatibility.ts +++ b/app/src/protyle/util/compatibility.ts @@ -110,6 +110,10 @@ export const isHuawei = () => { return window.siyuan.config.system.osPlatform.toLowerCase().indexOf("huawei") > -1; }; +export const isDisabledFeature = (feature: string): boolean => { + return window.siyuan.config.system.disabledFeatures.indexOf(feature) > -1; +} + export const isIPhone = () => { return navigator.userAgent.indexOf("iPhone") > -1; }; diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.ts index af1d6422c..5a1a9362d 100644 --- a/app/src/types/config.d.ts +++ b/app/src/types/config.d.ts @@ -1521,6 +1521,10 @@ declare namespace Config { * The absolute path of the workspace directory */ workspaceDir: string; + /** + * Disabled features. + */ + disabledFeatures: string[]; } /** diff --git a/kernel/conf/system.go b/kernel/conf/system.go index 6d51b4ce1..7640ca224 100644 --- a/kernel/conf/system.go +++ b/kernel/conf/system.go @@ -44,6 +44,8 @@ type System struct { DownloadInstallPkg bool `json:"downloadInstallPkg"` AutoLaunch2 int `json:"autoLaunch2"` // 0:不自动启动,1:自动启动,2:自动启动+隐藏主窗口 LockScreenMode int `json:"lockScreenMode"` // 0:手动,1:手动+跟随系统 https://github.com/siyuan-note/siyuan/issues/9087 + + DisabledFeatures []string `json:"disabledFeatures"` } func NewSystem() *System { diff --git a/kernel/mobile/kernel.go b/kernel/mobile/kernel.go index 900238fcf..7e2e01a79 100644 --- a/kernel/mobile/kernel.go +++ b/kernel/mobile/kernel.go @@ -114,3 +114,7 @@ func SetTimezone(container, appDir, timezoneID string) { } time.Local = z } + +func DisableFeature(feature string) { + util.DisableFeature(feature) +} diff --git a/kernel/model/conf.go b/kernel/model/conf.go index fd71dcb33..67947f333 100644 --- a/kernel/model/conf.go +++ b/kernel/model/conf.go @@ -220,6 +220,7 @@ func InitConf() { util.UseSingleLineSave = Conf.FileTree.UseSingleLineSave util.CurrentCloudRegion = Conf.CloudRegion + Conf.System.DisabledFeatures = util.DisabledFeatures if nil == Conf.Tag { Conf.Tag = conf.NewTag() diff --git a/kernel/util/runtime.go b/kernel/util/runtime.go index 4182d7042..387b3d464 100644 --- a/kernel/util/runtime.go +++ b/kernel/util/runtime.go @@ -38,6 +38,13 @@ import ( "github.com/siyuan-note/logging" ) +var DisabledFeatures []string + +func DisableFeature(feature string) { + DisabledFeatures = append(DisabledFeatures, feature) + DisabledFeatures = gulu.Str.RemoveDuplicatedElem(DisabledFeatures) +} + // UseSingleLineSave 是否使用单行保存 .sy 和数据库 .json 文件。 var UseSingleLineSave = true @@ -88,6 +95,9 @@ func logBootInfo() { " * database [ver=%s]\n"+ " * workspace directory [%s]", Ver, runtime.GOARCH, plat, os.Getpid(), Mode, WorkingDir, ReadOnly, Container, DatabaseVer, WorkspaceDir) + if 0 < len(DisabledFeatures) { + logging.LogInfof("disabled features [%s]", strings.Join(DisabledFeatures, ", ")) + } } func RandomSleep(minMills, maxMills int) {