Skip to content

Commit

Permalink
问题修复与体验优化 #606
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed Apr 1, 2024
1 parent 16dfa93 commit af1dda0
Show file tree
Hide file tree
Showing 21 changed files with 143 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = false
Expand Down
5 changes: 1 addition & 4 deletions .github/README_Sillot.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@

## 彖乄驱动

汐洛始终代表先进恣产力,始终拥护全球先进开源力量,坚定不移推动新彖乄面向未来持续发展。
汐洛始终代表先进恣产力,始终拥抱全球先进开源力量,坚定不移推动新彖乄面向未来持续发展。

<p align="center">
<img alt="framework" src="../screenshots/sillot/framework.png">
</p>

## 极致优雅

Expand Down
2 changes: 1 addition & 1 deletion app/appearance/langs/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@
"about13": "API token",
"about14": "调用 API 时需要通过该 token 进行鉴权",
"about17": "设置为 <code class='fn__code'>直接连接</code> 时不启用代理",
"about18": "使用非环回地址(<code class=\"fn__code\">127.0.0.1</code>/<code class=\"fn__code\">[::1]</code>)时请先设置 访问授权码",
"about18": "未设置访问授权码时仅可通过环回地址(<code class=\"fn__code\">127.0.0.1</code>/<code class=\"fn__code\">[::1]</code>)访问",
"checkUpdate": "检查更新",
"currentVer": "当前版本",
"downloadLatestVer": "<a href=\"https://b3log.org/siyuan/download.html\", target=\"_blank\">下载最新版</a>",
Expand Down
1 change: 1 addition & 0 deletions app/src/boot/onGetConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export const initWindow = async (app: App) => {
ipcRenderer.send(Constants.SIYUAN_CMD, "closeButtonBehavior");
}
} else {
console.warn("initWindow -> exitSiYuan() involved (winOnClose)");
exitSiYuan();
}
},
Expand Down
4 changes: 2 additions & 2 deletions app/src/config/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ ${
const networkServeElement = about.element.querySelector("#networkServe") as HTMLInputElement;
networkServeElement.addEventListener("change", () => {
fetchPost("/api/system/setNetworkServe", {networkServe: networkServeElement.checked}, () => {
if (window.JSAndroid && networkServeElement.checked) {
if (window.JSAndroid && networkServeElement.checked) { // 安卓平板
window.JSAndroid?.requestPermissionActivity("Battery","注意:后台稳定伺服会消耗额外电量","coldRestart");
} else if (window.JSAndroid) {
window.JSAndroid?.restartSillotAndroid();
window.Sillot?.androidRestartSiYuan();
} else {
exportLayout({
errorExit: true,
Expand Down
5 changes: 5 additions & 0 deletions app/src/dialog/processSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export const kernelError = () => {
if (document.querySelector("#errorLog")) {
return;
}
if (window.JSAndroid) {
window.JSAndroid.androidReboot();
return;
}
let iosReStart = "";
if (isInIOS()) {
iosReStart = `<div class="fn__hr"></div><div class="fn__flex"><div class="fn__flex-1"></div><button class="b3-button">${window.siyuan.languages.retry}</button></div>`;
Expand Down Expand Up @@ -268,6 +272,7 @@ export const transactionError = () => {
dialog.element.setAttribute("data-key", Constants.DIALOG_STATEEXCEPTED);
const btnsElement = dialog.element.querySelectorAll(".b3-button");
btnsElement[0].addEventListener("click", () => {
console.warn(`transactionError ${btnsElement[0]}.onClick -> exitSiYuan() involved`);
/// #if MOBILE
exitSiYuan();
/// #else
Expand Down
12 changes: 11 additions & 1 deletion app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { initMessage } from "./dialog/message";
import { getAllTabs } from "./layout/getAll";
import { getLocalStorage } from "./protyle/util/compatibility";
import { importIDB } from "./sillot/util/sillot-idb-backup-and-restore";
import { exportIDB, importIDB } from "./sillot/util/sillot-idb-backup-and-restore";
import { SillotEnv } from "./sillot";
import {getSearch} from "./util/functions";
import {hideAllElements} from "./protyle/ui/hideElements";
Expand Down Expand Up @@ -151,6 +151,16 @@ export class App {
}),
};
new SillotEnv();
window.Sillot.androidRestartSiYuan = ()=>{
const overlay = document.querySelector('#SillotOverlay') as HTMLElement;
overlay.style.display = "block";
exportIDB().then(() => {
hideAllElements(["util"]);
fetchPost("/api/sillot/androidReboot", {force: true}, (response) => {
window.location.href = "siyuan://androidRestartSiYuan";
});
})
};

fetchPost("/api/system/getConf", {}, async (response) => {
addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript");
Expand Down
2 changes: 2 additions & 0 deletions app/src/menus/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
fetchPost("/api/system/setWorkspaceDir", {
path: openPath
}, () => {
console.warn(`workspaceMenu -> exitSiYuan() involved (${window.siyuan.languages.openBy})`);
exitSiYuan();
});
});
Expand Down Expand Up @@ -205,6 +206,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => {
fetchPost("/api/system/setWorkspaceDir", {
path: item.path
}, () => {
console.warn(`workspaceMenu -> exitSiYuan() involved (${pathPosix().basename(item.path)})`);
exitSiYuan();
});
});
Expand Down
16 changes: 14 additions & 2 deletions app/src/mobile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {saveScroll} from "../protyle/scroll/saveScroll";
import {removeBlock} from "../protyle/wysiwyg/remove";
import {isNotEditBlock} from "../protyle/wysiwyg/getBlock";
import {updateCardHV} from "../card/util";
import { exportIDB } from "../sillot/util/sillot-idb-backup-and-restore";
import {hideAllElements, hideElements} from "../protyle/ui/hideElements";

class App {
public plugins: import("../plugin").Plugin[] = [];
Expand Down Expand Up @@ -62,6 +64,16 @@ class App {
})
};
new SillotEnv();
window.Sillot.androidRestartSiYuan = ()=>{
const overlay = document.querySelector('#SillotOverlay') as HTMLElement;
overlay.style.display = "block";
exportIDB().then(() => {
hideAllElements(["util"]);
fetchPost("/api/sillot/androidReboot", {force: true}, (response) => {
window.location.href = "siyuan://androidRestartSiYuan";
});
})
};
// 不能使用 touchstart,否则会被 event.stopImmediatePropagation() 阻塞
window.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
if (!window.siyuan.menus.menu.element.contains(event.target) && !hasClosestByAttribute(event.target, "data-menu", "true")) {
Expand All @@ -77,10 +89,10 @@ class App {
}
});
window.addEventListener("beforeunload", () => {
saveScroll(window.siyuan.mobile.editor?.protyle);
window.siyuan.mobile.editor?.protyle ? saveScroll(window.siyuan.mobile.editor.protyle) : null;
}, false);
window.addEventListener("pagehide", () => {
saveScroll(window.siyuan.mobile.editor?.protyle);
window.siyuan.mobile.editor?.protyle ? saveScroll(window.siyuan.mobile.editor.protyle) : null;
}, false);
// 判断手机横竖屏状态
window.matchMedia("(orientation:portrait)").addEventListener("change", () => {
Expand Down
1 change: 1 addition & 0 deletions app/src/mobile/menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export const initRightMenu = (app: App) => {
event.stopPropagation();
break;
} else if (target.id === "menuSafeQuit") {
console.warn("(mobile) menuSafeQuit -> exitSiYuan() involved");
exitSiYuan();
event.preventDefault();
event.stopPropagation();
Expand Down
4 changes: 3 additions & 1 deletion app/src/mobile/settings/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ ${
fetchPost("/api/system/setWorkspaceDir", {
path: openPath
}, () => {
console.warn(`(mobile) initAbout ${btnsElement[1]}.onClick -> exitSiYuan() involved (openWorkspace)`);
exitSiYuan();
});
});
Expand Down Expand Up @@ -357,6 +358,7 @@ ${
fetchPost("/api/system/setWorkspaceDir", {
path: target.getAttribute("data-path")
}, () => {
console.warn("(mobile) initAbout confirmDialog -> exitSiYuan() involved (creatWorkspace)");
exitSiYuan();
});
});
Expand All @@ -383,7 +385,7 @@ ${
if(networkServeElement.checked){
window.JSAndroid?.requestPermissionActivity("Battery","注意:后台稳定伺服会消耗额外电量","coldRestart");
} else {
window.JSAndroid?.restartSillotAndroid();
window.Sillot?.androidRestartSiYuan();
}
});
});
Expand Down
1 change: 1 addition & 0 deletions app/src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ interface Window {
requestPermission(id: string, Msg: string): boolean
exitSillotAndroid(): void
restartSillotAndroid(): void
androidReboot(): void
savePictureByURL(uri: string): void
// sillot extend end
returnDesktop(): void
Expand Down
1 change: 1 addition & 0 deletions app/src/types/sillot.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface ISillot {
hljsRender: any;
};
lute: Lute;
androidRestartSiYuan: ()=>void;
}

interface ISout {
Expand Down
23 changes: 12 additions & 11 deletions app/stage/auth.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions kernel/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("GET", "/api/sillot/getAppConfigesStore", getAppConfigesStore)
ginServer.Handle("POST", "/api/sillot/getConfigesStore", getConfigesStore)
ginServer.Handle("POST", "/api/sillot/setConfigesStore", setConfigesStore)
ginServer.Handle("POST", "/api/sillot/androidReboot", androidReboot, model.Ready)

// 不需要鉴权

Expand Down
28 changes: 28 additions & 0 deletions kernel/api/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,3 +504,31 @@ func exit(c *gin.Context) {
ret.Data = map[string]interface{}{"closeTimeout": 0}
}
}

func androidReboot(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

arg, ok := util.JsonArg(c, ret)
if !ok {
return
}

forceArg := arg["force"]
var force bool
if nil != forceArg {
force = forceArg.(bool)
}

exitCode := model.Close2(force, true)
ret.Code = exitCode
switch exitCode {
case 0:
case 1: // 同步执行失败
ret.Msg = model.Conf.Language(96) + "<div class=\"fn__space\"></div><button class=\"b3-button b3-button--white\">" + model.Conf.Language(97) + "</button>"
ret.Data = map[string]interface{}{"closeTimeout": 0}
case 2: // 提示新安装包
ret.Msg = model.Conf.Language(61)
ret.Data = map[string]interface{}{"closeTimeout": 0}
}
}
54 changes: 54 additions & 0 deletions kernel/model/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,60 @@ func Close(force, setCurrentWorkspace bool, execInstallPkg int) (exitCode int) {
}()
return
}
func Close2(force, setCurrentWorkspace bool) (exitCode int) {
exitLock.Lock()
defer exitLock.Unlock()

util.PushMsg(Conf.Language(95), 10000*60)

if !force {
if Conf.Sync.Enabled && 3 != Conf.Sync.Mode &&
((IsSubscriber() && conf.ProviderSiYuan == Conf.Sync.Provider) || conf.ProviderSiYuan != Conf.Sync.Provider) {
syncData(true, false)
if 0 != ExitSyncSucc {
exitCode = 1
return
}
}
}

// Close the user guide when exiting https://github.com/siyuan-note/siyuan/issues/10322
closeUserGuide()

util.IsExiting.Store(true)

Conf.Close()
sql.CloseDatabase()
treenode.SaveBlockTree(false)
SaveAssetsTexts()
clearWorkspaceTemp()
clearCorruptedNotebooks()
clearPortJSON()

if setCurrentWorkspace {
// 将当前工作空间放到工作空间列表的最后一个
// Open the last workspace by default https://github.com/siyuan-note/siyuan/issues/10570
workspacePaths, err := util.ReadWorkspacePaths()
if nil != err {
logging.LogErrorf("read workspace paths failed: %s", err)
} else {
workspacePaths = gulu.Str.RemoveElem(workspacePaths, util.WorkspaceDir)
workspacePaths = append(workspacePaths, util.WorkspaceDir)
util.WriteWorkspacePaths(workspacePaths)
}
}

util.UnlockWorkspace()

closeSyncWebSocket()
go func() {
time.Sleep(500 * time.Millisecond)
logging.LogInfof("exited kernel")
util.WebSocketServer.Close()
// os.Exit(logging.ExitCodeOk)
}()
return
}

var CustomEmojis = sync.Map{}

Expand Down
3 changes: 2 additions & 1 deletion kernel/model/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ func Export2Liandi(id string) (err error) {
}

func ExportSystemLog() (zipPath string) {
exportFolder := filepath.Join(util.TempDir, "export", "system-log")
exportFolder := filepath.Join(util.TempDir, "export", "sillot-system-log")
logging.LogDebugf("(model) New ExportSystemLog() involved -> %s.zip", zipPath)
os.RemoveAll(exportFolder)
if err := os.MkdirAll(exportFolder, 0755); nil != err {
logging.LogErrorf("create export temp folder failed: %s", err)
Expand Down
2 changes: 1 addition & 1 deletion kernel/model/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func HookDesktopUIProcJob() {
Close(false, true, 1)
}

var uiProcNames = []string{"siyuan", "electron"}
var uiProcNames = []string{"sillot", "electron"}

// getAttachedUIProcCount 获取已经附加的 UI 进程数。
func getAttachedUIProcCount() (ret int) {
Expand Down
2 changes: 1 addition & 1 deletion kernel/util/working_mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func initWorkspaceDirMobile(workspaceBaseDir string) {
}
if oldConf && oldData && oldTemp {
for _, entry := range entries {
if "home" == entry.Name() || "siyuan" == entry.Name() {
if "home" == entry.Name() || "sillot" == entry.Name() {
continue
}

Expand Down
Binary file removed screenshots/sillot/framework.png
Binary file not shown.

0 comments on commit af1dda0

Please sign in to comment.