Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

1.0 KB
Raw Blame
// SiYuan - https://github.com/siyuan-note/siyuan
// Copyright (c) 2020-present, b3log.org
// SPDX-License-Identifier: AGPL-3.0-or-later

package model

import "github.com/siyuan-note/siyuan/kernel/conf"

// SetEncryptedNotebookFollowSystemLock 将锁屏策略保存在本机系统配置中,不参与密钥备份认证。
func SetEncryptedNotebookFollowSystemLock(enabled bool) {
	UpdateSystemConf(func(s *conf.System) { s.EncryptedNotebookFollowSystemLock = enabled })
}

// LockEncryptedNotebooksOnSystemLock 等待正在解锁的笔记本完成,再复用卸载流程保存内容并清除密钥。
func LockEncryptedNotebooksOnSystemLock() {
	Conf.m.RLock()
	enabled := Conf.System.Load().EncryptedNotebookFollowSystemLock
	Conf.m.RUnlock()
	if !enabled {
		return
	}

	notebookCryptoMu.Lock()
	cachedDEKsLock.RLock()
	boxIDs := make([]string, 0, len(cachedDEKs))
	for boxID := range cachedDEKs {
		boxIDs = append(boxIDs, boxID)
	}
	cachedDEKsLock.RUnlock()
	notebookCryptoMu.Unlock()
	for _, boxID := range boxIDs {
		Unmount(boxID)
	}
}