Skip to content

Commit

Permalink
fix: 优化设备判断
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Jan 11, 2023
1 parent 6b099eb commit ddfb467
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 73 deletions.
10 changes: 5 additions & 5 deletions components/blog/BlogMain.vue
Expand Up @@ -143,7 +143,7 @@
<el-alert
class="top-data-tip"
:title="
isInSiyuan
isInSiyuanEnv
? $t('blog.top-data-tip.siyuan')
: $t('blog.top-data-tip')
"
Expand Down Expand Up @@ -185,7 +185,7 @@ import { onMounted, ref } from "vue"
import { LogFactory } from "~/utils/logUtil"
import { Post } from "~/utils/models/post"
import { goToPage } from "~/utils/otherlib/ChromeUtil"
import { getPageId, inSiyuan } from "~/utils/platform/siyuan/siyuanUtil"
import { getPageId, isInSiyuan } from "~/utils/platform/siyuan/siyuanUtil"
import { SiYuanApiAdaptor } from "~/utils/platform/siyuan/siYuanApiAdaptor"
import { mdToHtml, removeTitleNumber } from "~/utils/htmlUtil"
import { getByLength } from "~/utils/strUtil"
Expand Down Expand Up @@ -213,7 +213,7 @@ const showPicgo = ref(false)
const postDetail = ref()
const publishData = ref()
const isInSiyuan = ref(false)
const isInSiyuanEnv = ref(false)
const isNewWin = ref(true)
const state = ref("")
Expand Down Expand Up @@ -447,7 +447,7 @@ const handleNewWinPicgo = (index, row) => {
}
const initPage = async () => {
isInSiyuan.value = inSiyuan()
isInSiyuanEnv.value = isInSiyuan()
const publishCfg = getPublishCfg()
isNewWin.value = parseBoolean(publishCfg.newWin)
Expand All @@ -465,7 +465,7 @@ const reloadTableData = async () => {
try {
const siyuanApi = new SiYuanApiAdaptor()
if (isInSiyuan.value || isInSiyuanNewWinBrowser()) {
if (isInSiyuanEnv.value || isInSiyuanNewWinBrowser()) {
const postid = await getPageId()
logger.warn("处于生产环境,父文档ID为=>", postid)
Expand Down
2 changes: 1 addition & 1 deletion components/publish/tab/main/CommonBlogMain.vue
Expand Up @@ -253,7 +253,7 @@
@change="picgoPostMethods.picgoOnChange"
/>
<el-alert
v-if="picgoPostData.picgoEnabled"
v-if="false && picgoPostData.picgoEnabled"
:closable="false"
:title="$t('github.post.picgo.use.tip')"
type="warning"
Expand Down
2 changes: 1 addition & 1 deletion components/publish/tab/main/GithubMain.vue
Expand Up @@ -455,7 +455,7 @@
@change="picgoPostMethods.picgoOnChange"
/>
<el-alert
v-if="picgoPostData.picgoEnabled"
v-if="false && picgoPostData.picgoEnabled"
:closable="false"
:title="$t('github.post.picgo.use.tip')"
type="warning"
Expand Down
4 changes: 2 additions & 2 deletions composables/picgo/picgoCommonCom.ts
Expand Up @@ -24,7 +24,7 @@
*/

import { reactive } from "vue"
import { inSiyuan } from "~/utils/platform/siyuan/siyuanUtil"
import { isInSiyuan } from "~/utils/platform/siyuan/siyuanUtil"
import { isInSiyuanNewWinBrowser } from "~/utils/otherlib/siyuanBrowserUtil"

/**
Expand All @@ -35,7 +35,7 @@ import { isInSiyuanNewWinBrowser } from "~/utils/otherlib/siyuanBrowserUtil"
export const usePicgoCommon = () => {
// private data
const isDev = process.env.NODE_ENV === "development"
const isSiyuanOrSiyuanNewWin = inSiyuan() || isInSiyuanNewWinBrowser()
const isSiyuanOrSiyuanNewWin = isInSiyuan() || isInSiyuanNewWinBrowser()

// public data
const picgoCommonData = reactive({
Expand Down
4 changes: 2 additions & 2 deletions composables/picgo/picgoUploadCom.ts
Expand Up @@ -27,7 +27,7 @@ import { reactive } from "vue"
import { ElMessage, ElMessageBox } from "element-plus"
import { useI18n } from "vue-i18n"
import { LogFactory } from "~/utils/logUtil"
import { inSiyuan } from "~/utils/platform/siyuan/siyuanUtil"
import { isInSiyuan } from "~/utils/platform/siyuan/siyuanUtil"
import { isInSiyuanNewWinBrowser } from "~/utils/otherlib/siyuanBrowserUtil"
import { uploadByPicGO } from "~/utils/otherlib/picgoUtil"
import { isElectron } from "~/utils/browserUtil"
Expand Down Expand Up @@ -108,7 +108,7 @@ export const usePicgoUpload = (props, deps, refs) => {
return
}

if (!inSiyuan() && !isInSiyuanNewWinBrowser()) {
if (!isInSiyuan() && !isInSiyuanNewWinBrowser()) {
ElMessage.error("非electron环境只能通过剪贴板上传")
picgoCommonData.isUploadLoading = false
return
Expand Down
16 changes: 10 additions & 6 deletions layouts/default/DefaultFooter.vue
Expand Up @@ -35,8 +35,12 @@
isDark ? $t("theme.mode.light") : $t("theme.mode.dark")
}}</span>

<span class="text" v-if="!isInSiyuan">.</span>
<span class="text s-dark" @click="changeSiyuanApi()" v-if="!isInSiyuan">
<span class="text" v-if="!isInSiyuanEnv">.</span>
<span
class="text s-dark"
@click="changeSiyuanApi()"
v-if="!isInSiyuanEnv"
>
{{ $t("blog.change.siyuan.api") }}
</span>

Expand Down Expand Up @@ -156,7 +160,7 @@ import { onMounted, reactive, ref } from "vue"
import { ElMessage, ElMessageBox, FormRules } from "element-plus"
import { useI18n } from "vue-i18n"
import { LogFactory } from "~/utils/logUtil"
import { inSiyuan } from "~/utils/platform/siyuan/siyuanUtil"
import { isInSiyuan } from "~/utils/platform/siyuan/siyuanUtil"
import {
getSiyuanCfg,
SiYuanConfig,
Expand All @@ -181,7 +185,7 @@ const { t } = useI18n()
const isDark = useDark()
const toggleDark = useToggle(isDark)
const isInSiyuan = ref(false)
const isInSiyuanEnv = ref(false)
const v = ref("0.0.3")
const formLabelWidth = "140px"
Expand Down Expand Up @@ -294,7 +298,7 @@ const handleSiyuanApiSetting = async (formEl) => {
}
const initConf = () => {
isInSiyuan.value = inSiyuan()
isInSiyuanEnv.value = isInSiyuan()
v.value = version
Expand All @@ -307,7 +311,7 @@ const initConf = () => {
}
onMounted(() => {
if (inSiyuan()) {
if (isInSiyuan()) {
logger.info("恭喜你,正在以挂件模式运行")
} else {
logger.info(
Expand Down
4 changes: 2 additions & 2 deletions layouts/default/DefaultHeader.vue
Expand Up @@ -187,7 +187,7 @@ import {
isInSiyuanNewWinBrowser,
} from "~/utils/otherlib/siyuanBrowserUtil"
import { ElMessage } from "element-plus"
import { getWidgetId, inSiyuan } from "~/utils/platform/siyuan/siyuanUtil"
import { getWidgetId, isInSiyuan } from "~/utils/platform/siyuan/siyuanUtil"
import { getPublishCfg } from "~/utils/publishUtil"
import { getBooleanEnv } from "~/utils/envUtil"
import { appendStr } from "~/utils/strUtil"
Expand Down Expand Up @@ -329,7 +329,7 @@ const pageIdChanged = () => {
onMounted(() => {
// 思源新窗口,或者思源挂件才会有这两个按钮
if (isInSiyuanNewWinBrowser() || inSiyuan()) {
if (isInSiyuanNewWinBrowser() || isInSiyuan()) {
// init
const publishCfg = getPublishCfg()
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "sy-post-publisher",
"private": true,
"version": "0.6.4",
"version": "0.6.5",
"packageManager": "pnpm@7.18.1",
"scripts": {
"serve": "vercel dev --listen 6006",
Expand All @@ -20,7 +20,7 @@
"extChromeWin": "pwsh scripts/ext.ps1",
"extChromeDev": "bash scripts/extDev.sh",
"extFirefox": "bash scripts/extFV2.sh",
"newVersion": "cd scripts && python3 version.py 0.6.4 && cd ../",
"newVersion": "cd scripts && python3 version.py 0.6.5 && cd ../",
"dcfg": "bash scripts/devWidgetConfig.sh"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions pages/index/App.vue
@@ -1,5 +1,5 @@
<!--
- Copyright (c) 2022, Terwer . All rights reserved.
- Copyright (c) 2022-2023, Terwer . All rights reserved.
- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-
- This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -44,7 +44,7 @@ import { onMounted, ref } from "vue"
import { LogFactory } from "~/utils/logUtil"
import { getPageId, getWidgetId } from "~/utils/platform/siyuan/siyuanUtil"
import { SiYuanApiAdaptor } from "~/utils/platform/siyuan/siYuanApiAdaptor"
import { isInChromeExtension } from "~/utils/otherlib/ChromeUtil"
import { isInChromeExtension } from "~/utils/browserUtil"
import {
getSiyuanNewWinPageId,
isInSiyuanNewWinBrowser,
Expand Down
2 changes: 1 addition & 1 deletion plugins/vue-hljs/lib/vue-hljs/main.js
Expand Up @@ -43,7 +43,7 @@ import "../codecopy/codecopy.css"
import "./vs.css"
import * as plantumlEncoder from "plantuml-encoder"
import { unescapeHTML } from "~/utils/strUtil"
import { isInChromeExtension } from "~/utils/otherlib/ChromeUtil.js"
import { isInChromeExtension } from "~/utils/browserUtil"

const vueHljs = {}

Expand Down
2 changes: 1 addition & 1 deletion public/manifest.dev.json
@@ -1,6 +1,6 @@
{
"name": "开发版 - 思源笔记发布辅助工具",
"version": "0.6.3",
"version": "0.6.5",
"manifest_version": 3,
"author": "terwer",
"description": "思源笔记发布辅助工具,支持博客式只读浏览,多平台文章发布。",
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.prod.json
@@ -1,6 +1,6 @@
{
"name": "思源笔记发布辅助工具",
"version": "0.6.3",
"version": "0.6.5",
"manifest_version": 3,
"author": "terwer",
"icons": {
Expand Down
2 changes: 1 addition & 1 deletion public/mv2/manifest-v2-for-firefox.json
@@ -1,6 +1,6 @@
{
"name": "开发版 - 思源笔记发布辅助工具",
"version": "0.6.3",
"version": "0.6.5",
"manifest_version": 2,
"author": "terwer",
"icons": {
Expand Down
2 changes: 1 addition & 1 deletion public/widget.json
Expand Up @@ -2,5 +2,5 @@
"name": "sy-post-publisher",
"author": "terwer",
"url": "https://github.com/terwer/src-sy-post-publisher",
"version": "0.6.3"
"version": "0.6.5"
}
10 changes: 10 additions & 0 deletions utils/browserUtil.ts
Expand Up @@ -176,3 +176,13 @@ export const copyToClipboardInBrowser = (text) => {
}
}
}

/**
* 检测是否运行在Chrome插件中
*/
export function isInChromeExtension() {
if (!isBrowser()) {
return false
}
return window.location.href.indexOf("chrome-extension://") > -1
}
70 changes: 70 additions & 0 deletions utils/deviceUtil.ts
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

import { isInSiyuan } from "~/utils/platform/siyuan/siyuanUtil"
import { isInSiyuanNewWinBrowser } from "~/utils/otherlib/siyuanBrowserUtil"
import { isInChromeExtension } from "~/utils/browserUtil"

export enum DeviceType {
/**
* 思源笔记新窗口
*/
DeviceType_Siyuan_NewWin,
/**
* 思源笔记挂件
*/
DeviceType_Siyuan_Widget,
DeviceType_Chrome_Extension,
DeviceType_Chrome_Browser,
}

/**
* 设备相关
* @author terwer
* @since 0.6.4
*/
export class DeviceUtil {
/**
* 获取当前设备
*/
public static getDevice() {
// 思源笔记挂件
if (isInSiyuan()) {
return DeviceType.DeviceType_Siyuan_Widget
}

// 思源新窗口
if (isInSiyuanNewWinBrowser()) {
return DeviceType.DeviceType_Siyuan_NewWin
}

// Chrome浏览器插件
if (isInChromeExtension()) {
return DeviceType.DeviceType_Chrome_Extension
}

return DeviceType.DeviceType_Chrome_Browser
}
}

0 comments on commit ddfb467

Please sign in to comment.