Skip to content

Commit

Permalink
feat: add siyuan browser device
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Apr 15, 2023
1 parent d288f33 commit 3ee397c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 0 additions & 1 deletion apps/zhi-core/src/theme/zhi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class Zhi {
*/
public async init(): Promise<void> {
try {
alert(this.runAs)
this.logger.info(`Theme runAs ${this.runAs}`)
this.logger.info("Theme inited.")
} catch (e) {
Expand Down
5 changes: 5 additions & 0 deletions apps/zhi-device-detection/src/deviceDetection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class DeviceDetection {
return DeviceTypeEnum.DeviceType_Siyuan_MainWin
}

// 思源打开的浏览器
if (SiyuanDevice.isInSiyuanBrowser()) {
return DeviceTypeEnum.DeviceType_Siyuan_Browser
}

// Chrome浏览器插件
if (BrowserUtil.isInChromeExtension()) {
return DeviceTypeEnum.DeviceType_Chrome_Extension
Expand Down
5 changes: 5 additions & 0 deletions apps/zhi-device-detection/src/lib/deviceTypeEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ enum DeviceTypeEnum {
*/
DeviceType_Siyuan_MainWin = "Siyuan_MainWindow",

/**
* 思源打开的浏览器
*/
DeviceType_Siyuan_Browser = "Siyuan_Browser",

/**
* Google Chrome浏览器插件
*/
Expand Down
10 changes: 10 additions & 0 deletions apps/zhi-device-detection/src/lib/siyuanDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ class SiyuanDevice {
*/
return typeof (window as any).terwer !== "undefined" || typeof (window as any).siyuanNewWin !== "undefined"
}

/**
* 检测是否运行在思源打开的浏览器中
*/
public static isInSiyuanBrowser() {
if (!BrowserUtil.isInBrowser) {
return false
}
return typeof (window as any).siyuan !== "undefined" && typeof (window as any).Lute !== "undefined"
}
}

export default SiyuanDevice

0 comments on commit 3ee397c

Please sign in to comment.