diff --git a/app/src/config/about.ts b/app/src/config/about.ts index 3a090527a..7f1371c8b 100644 --- a/app/src/config/about.ts +++ b/app/src/config/about.ts @@ -247,10 +247,6 @@ export const about = { searchData.idPath = ""; localStorage.setItem(Constants.LOCAL_SEARCHEDATA, JSON.stringify(searchData)); } - localStorage.removeItem(Constants.LOCAL_DAILYNOTEID); - localStorage.removeItem(Constants.LOCAL_DOCINFO); - localStorage.removeItem(Constants.LOCAL_HISTORYNOTEID); - localStorage.removeItem("pdfjs.history"); exportLayout(false, () => { exitSiYuan(); }); diff --git a/app/src/config/appearance.ts b/app/src/config/appearance.ts index 247006e98..4156804f5 100644 --- a/app/src/config/appearance.ts +++ b/app/src/config/appearance.ts @@ -3,7 +3,7 @@ import {ipcRenderer, shell} from "electron"; import * as path from "path"; /// #endif import {Constants} from "../constants"; -import {exportLayout} from "../layout/util"; +import {exportLayout, resetLayout} from "../layout/util"; import {isBrowser} from "../util/functions"; import {fetchPost} from "../util/fetch"; import {loadAssets} from "../util/assets"; @@ -217,9 +217,7 @@ export const appearance = { openColorPicker(); }); appearance.element.querySelector("#resetLayout").addEventListener("click", () => { - fetchPost("/api/system/setUILayout", {layout: {}}, () => { - window.location.reload(); - }); + resetLayout() }); /// #if !BROWSER appearance.element.querySelector("#appearanceOpenIcon").addEventListener("click", () => { diff --git a/app/src/constants.ts b/app/src/constants.ts index 87bf17f0e..bf17913f3 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -61,7 +61,7 @@ export abstract class Constants { // localstorage public static readonly LOCAL_SEARCHEDATA = "local-searchedata"; public static readonly LOCAL_SEARCHETABDATA = "local-searchetabdata"; - public static readonly LOCAL_DOCINFO = "local-docinfo"; + public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile public static readonly LOCAL_DAILYNOTEID = "local-dailynoteid"; public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid"; public static readonly LOCAL_CODELANG = "local-codelang"; diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts index 4ab45ef1c..1c8cba7ab 100644 --- a/app/src/layout/util.ts +++ b/app/src/layout/util.ts @@ -136,6 +136,12 @@ const dockToJSON = (dock: Dock) => { return json; }; +export const resetLayout = () => { + fetchPost("/api/system/setUILayout", {layout: {}}, () => { + window.location.reload(); + }); +}; + export const exportLayout = (reload: boolean, cb?: () => void) => { const useElement = document.querySelector("#barDock use"); if (!useElement) { diff --git a/app/src/mobile/index.ts b/app/src/mobile/index.ts index e0564f91c..3aae2f85c 100644 --- a/app/src/mobile/index.ts +++ b/app/src/mobile/index.ts @@ -10,7 +10,7 @@ import {addBaseURL, setNoteBook} from "../util/pathName"; import {handleTouchEnd, handleTouchMove, handleTouchStart} from "./util/touch"; import {fetchGet, fetchPost} from "../util/fetch"; import {initFramework} from "./util/initFramework"; -import {initAssets, loadAssets} from "../util/assets"; +import {addGA, initAssets, loadAssets} from "../util/assets"; import {promiseTransactions} from "../protyle/wysiwyg/transaction"; import {bootSync} from "../dialog/processSystem"; import {initMessage} from "../dialog/message"; @@ -62,6 +62,7 @@ class App { } initMessage(); }); + addGA(); }); if (navigator.userAgent.indexOf("iPhone") > -1) { document.addEventListener("touchstart", handleTouchStart, false); diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts index 556978863..effdbd773 100644 --- a/app/src/protyle/util/compatibility.ts +++ b/app/src/protyle/util/compatibility.ts @@ -131,3 +131,11 @@ export const hotKey2Electron = (key: string) => { } return electronKey + key.substr(key.length - 1); }; + +export const setLocalStorage = () => { + +} + +export const exportLocalStorage = () => { + +} diff --git a/app/src/util/assets.ts b/app/src/util/assets.ts index 6e1582574..99c11e4a4 100644 --- a/app/src/util/assets.ts +++ b/app/src/util/assets.ts @@ -122,6 +122,38 @@ export const initAssets = () => { } }; +export const addGA = () => { + if (!window.siyuan.config.system.disableGoogleAnalytics) { + addScript("https://www.googletagmanager.com/gtag/js?id=G-L7WEXVQCR9", "gaScript").then(() => { + try { + window.dataLayer = window.dataLayer || []; + window.gtag = function (...args) { + window.dataLayer.push(args); + }; + window.gtag("js", new Date()); + window.gtag("config", "G-L7WEXVQCR9"); + const para = { + "version": Constants.SIYUAN_VERSION, + "container": window.siyuan.config.system.container, + "isLoggedIn": "false", + "subscriptionStatus": "-1", + "subscriptionPlan": "-1", + "subscriptionType": "-1", + }; + if (window.siyuan.user) { + para.isLoggedIn = "true"; + para.subscriptionStatus = window.siyuan.user.userSiYuanSubscriptionStatus.toString(); + para.subscriptionPlan = window.siyuan.user.userSiYuanSubscriptionPlan.toString(); + para.subscriptionType = window.siyuan.user.userSiYuanSubscriptionType.toString(); + } + window.gtag("event", Constants.ANALYTICS_EVT_ON_GET_CONFIG, para); + } catch (e) { + console.error(e); + } + }); + } +} + export const setInlineStyle = (set = true) => { const height = Math.floor(window.siyuan.config.editor.fontSize * 1.625); let style = `.b3-typography, .protyle-wysiwyg, .protyle-title {font-size:${window.siyuan.config.editor.fontSize}px !important} diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts index 4afa712de..3ea2a092c 100644 --- a/app/src/util/onGetConfig.ts +++ b/app/src/util/onGetConfig.ts @@ -1,5 +1,5 @@ import {openSearch} from "../search/spread"; -import {exportLayout, JSONToLayout, resizeDrag, resizeTabs} from "../layout/util"; +import {exportLayout, JSONToLayout, resetLayout, resizeDrag, resizeTabs} from "../layout/util"; import {hotKey2Electron, updateHotkeyTip} from "../protyle/util/compatibility"; /// #if !BROWSER import {dialog, getCurrentWindow} from "@electron/remote"; @@ -15,7 +15,7 @@ import {globalShortcut} from "./globalShortcut"; import {fetchPost} from "./fetch"; import {mountHelp, newDailyNote} from "./mount"; import {MenuItem} from "../menus/Menu"; -import {initAssets, loadAssets, setInlineStyle, setMode} from "./assets"; +import {addGA, initAssets, loadAssets, setInlineStyle, setMode} from "./assets"; import {renderSnippet} from "../config/util/snippets"; import {getOpenNotebookCount} from "./pathName"; import {openFileById} from "../editor/util"; @@ -138,9 +138,7 @@ export const onGetConfig = (isStart: boolean) => { try { JSONToLayout(isStart); } catch (e) { - fetchPost("/api/system/setUILayout", {layout: {}}, () => { - window.location.reload(); - }); + resetLayout(); } }); initBar(); @@ -161,36 +159,7 @@ export const onGetConfig = (isStart: boolean) => { if (window.siyuan.config.newbie) { mountHelp(); } - - if (!window.siyuan.config.system.disableGoogleAnalytics) { - addScript("https://www.googletagmanager.com/gtag/js?id=G-L7WEXVQCR9", "gaScript").then(() => { - try { - window.dataLayer = window.dataLayer || []; - window.gtag = function (...args) { - window.dataLayer.push(args); - }; - window.gtag("js", new Date()); - window.gtag("config", "G-L7WEXVQCR9"); - const para = { - "version": Constants.SIYUAN_VERSION, - "container": window.siyuan.config.system.container, - "isLoggedIn": "false", - "subscriptionStatus": "-1", - "subscriptionPlan": "-1", - "subscriptionType": "-1", - }; - if (window.siyuan.user) { - para.isLoggedIn = "true"; - para.subscriptionStatus = window.siyuan.user.userSiYuanSubscriptionStatus.toString(); - para.subscriptionPlan = window.siyuan.user.userSiYuanSubscriptionPlan.toString(); - para.subscriptionType = window.siyuan.user.userSiYuanSubscriptionType.toString(); - } - window.gtag("event", Constants.ANALYTICS_EVT_ON_GET_CONFIG, para); - } catch (e) { - console.error(e); - } - }); - } + addGA(); }; const initBar = () => {