mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-29 04:39:53 +00:00
ui: set local file encryption in the core (#3227)
This commit is contained in:
parent
e6b0983c3e
commit
43b67ba157
6 changed files with 25 additions and 9 deletions
|
@ -257,7 +257,7 @@ func setXFTPConfig(_ cfg: XFTPFileConfig?) throws {
|
||||||
throw r
|
throw r
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiSetEncryptLocalFiles(_ enable: Boolean) throws {
|
func apiSetEncryptLocalFiles(_ enable: Bool) throws {
|
||||||
let r = chatSendCmdSync(.apiSetEncryptLocalFiles(enable: enable))
|
let r = chatSendCmdSync(.apiSetEncryptLocalFiles(enable: enable))
|
||||||
if case .cmdOk = r { return }
|
if case .cmdOk = r { return }
|
||||||
throw r
|
throw r
|
||||||
|
@ -1158,7 +1158,7 @@ func initializeChat(start: Bool, dbKey: String? = nil, refreshInvitations: Bool
|
||||||
try apiSetTempFolder(tempFolder: getTempFilesDirectory().path)
|
try apiSetTempFolder(tempFolder: getTempFilesDirectory().path)
|
||||||
try apiSetFilesFolder(filesFolder: getAppFilesDirectory().path)
|
try apiSetFilesFolder(filesFolder: getAppFilesDirectory().path)
|
||||||
try setXFTPConfig(getXFTPCfg())
|
try setXFTPConfig(getXFTPCfg())
|
||||||
// try apiSetEncryptLocalFiles(privacyEncryptLocalFilesGroupDefault.get())
|
try apiSetEncryptLocalFiles(privacyEncryptLocalFilesGroupDefault.get())
|
||||||
m.chatInitialized = true
|
m.chatInitialized = true
|
||||||
m.currentUser = try apiGetActiveUser()
|
m.currentUser = try apiGetActiveUser()
|
||||||
if m.currentUser == nil {
|
if m.currentUser == nil {
|
||||||
|
|
|
@ -66,6 +66,9 @@ struct PrivacySettings: View {
|
||||||
Section {
|
Section {
|
||||||
settingsRow("lock.doc") {
|
settingsRow("lock.doc") {
|
||||||
Toggle("Encrypt local files", isOn: $encryptLocalFiles)
|
Toggle("Encrypt local files", isOn: $encryptLocalFiles)
|
||||||
|
.onChange(of: encryptLocalFiles) {
|
||||||
|
setEncryptLocalFiles($0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
settingsRow("photo") {
|
settingsRow("photo") {
|
||||||
Toggle("Auto-accept images", isOn: $autoAcceptImages)
|
Toggle("Auto-accept images", isOn: $autoAcceptImages)
|
||||||
|
@ -183,6 +186,16 @@ struct PrivacySettings: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func setEncryptLocalFiles(_ enable: Bool) {
|
||||||
|
do {
|
||||||
|
try apiSetEncryptLocalFiles(enable)
|
||||||
|
} catch let error {
|
||||||
|
let err = responseError(error)
|
||||||
|
logger.error("apiSetEncryptLocalFiles \(err)")
|
||||||
|
alert = .error(title: "Error", error: "\(err)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func setOrAskSendReceiptsContacts(_ enable: Bool) {
|
private func setOrAskSendReceiptsContacts(_ enable: Bool) {
|
||||||
contactReceiptsOverrides = m.chats.reduce(0) { count, chat in
|
contactReceiptsOverrides = m.chats.reduce(0) { count, chat in
|
||||||
let sendRcpts = chat.chatInfo.contact?.chatSettings.sendRcpts
|
let sendRcpts = chat.chatInfo.contact?.chatSettings.sendRcpts
|
||||||
|
|
|
@ -216,7 +216,7 @@ func startChat() -> DBMigrationResult? {
|
||||||
try apiSetTempFolder(tempFolder: getTempFilesDirectory().path)
|
try apiSetTempFolder(tempFolder: getTempFilesDirectory().path)
|
||||||
try apiSetFilesFolder(filesFolder: getAppFilesDirectory().path)
|
try apiSetFilesFolder(filesFolder: getAppFilesDirectory().path)
|
||||||
try setXFTPConfig(xftpConfig)
|
try setXFTPConfig(xftpConfig)
|
||||||
// try apiSetEncryptLocalFiles(privacyEncryptLocalFilesGroupDefault.get())
|
try apiSetEncryptLocalFiles(privacyEncryptLocalFilesGroupDefault.get())
|
||||||
let justStarted = try apiStartChat()
|
let justStarted = try apiStartChat()
|
||||||
chatStarted = true
|
chatStarted = true
|
||||||
if justStarted {
|
if justStarted {
|
||||||
|
@ -352,8 +352,8 @@ func setXFTPConfig(_ cfg: XFTPFileConfig?) throws {
|
||||||
throw r
|
throw r
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiSetEncryptLocalFiles(_ enable: Boolean) throws {
|
func apiSetEncryptLocalFiles(_ enable: Bool) throws {
|
||||||
let r = chatSendCmdSync(.apiSetEncryptLocalFiles(enable: enable))
|
let r = sendSimpleXCmd(.apiSetEncryptLocalFiles(enable: enable))
|
||||||
if case .cmdOk = r { return }
|
if case .cmdOk = r { return }
|
||||||
throw r
|
throw r
|
||||||
}
|
}
|
||||||
|
|
|
@ -338,7 +338,7 @@ object ChatController {
|
||||||
apiSetTempFolder(coreTmpDir.absolutePath)
|
apiSetTempFolder(coreTmpDir.absolutePath)
|
||||||
apiSetFilesFolder(appFilesDir.absolutePath)
|
apiSetFilesFolder(appFilesDir.absolutePath)
|
||||||
apiSetXFTPConfig(getXFTPCfg())
|
apiSetXFTPConfig(getXFTPCfg())
|
||||||
// apiSetEncryptLocalFiles(appPrefs.privacyEncryptLocalFiles.get())
|
apiSetEncryptLocalFiles(appPrefs.privacyEncryptLocalFiles.get())
|
||||||
val justStarted = apiStartChat()
|
val justStarted = apiStartChat()
|
||||||
val users = listUsers()
|
val users = listUsers()
|
||||||
chatModel.users.clear()
|
chatModel.users.clear()
|
||||||
|
@ -1333,7 +1333,7 @@ object ChatController {
|
||||||
private suspend fun sendCommandOkResp(cmd: CC): Boolean {
|
private suspend fun sendCommandOkResp(cmd: CC): Boolean {
|
||||||
val r = sendCmd(cmd)
|
val r = sendCmd(cmd)
|
||||||
val ok = r is CR.CmdOk
|
val ok = r is CR.CmdOk
|
||||||
if (!ok) apiErrorAlert(cmd.cmdType, generalGetString(MR.strings.error), r)
|
if (!ok) apiErrorAlert(cmd.cmdType, generalGetString(MR.strings.error_alert_title), r)
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1942,7 +1942,7 @@ sealed class CC {
|
||||||
class ApiRejectContact(val contactReqId: Long): CC()
|
class ApiRejectContact(val contactReqId: Long): CC()
|
||||||
class ApiChatRead(val type: ChatType, val id: Long, val range: ItemRange): CC()
|
class ApiChatRead(val type: ChatType, val id: Long, val range: ItemRange): CC()
|
||||||
class ApiChatUnread(val type: ChatType, val id: Long, val unreadChat: Boolean): CC()
|
class ApiChatUnread(val type: ChatType, val id: Long, val unreadChat: Boolean): CC()
|
||||||
class ReceiveFile(val fileId: Long, val encrypt: Boolean?, val inline: Boolean?): CC()
|
class ReceiveFile(val fileId: Long, val encrypt: Boolean, val inline: Boolean?): CC()
|
||||||
class CancelFile(val fileId: Long): CC()
|
class CancelFile(val fileId: Long): CC()
|
||||||
class ShowVersion(): CC()
|
class ShowVersion(): CC()
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,9 @@ fun PrivacySettingsView(
|
||||||
SectionDividerSpaced()
|
SectionDividerSpaced()
|
||||||
|
|
||||||
SectionView(stringResource(MR.strings.settings_section_title_chats)) {
|
SectionView(stringResource(MR.strings.settings_section_title_chats)) {
|
||||||
SettingsPreferenceItem(painterResource(MR.images.ic_lock), stringResource(MR.strings.encrypt_local_files), chatModel.controller.appPrefs.privacyEncryptLocalFiles)
|
SettingsPreferenceItem(painterResource(MR.images.ic_lock), stringResource(MR.strings.encrypt_local_files), chatModel.controller.appPrefs.privacyEncryptLocalFiles, onChange = { enable ->
|
||||||
|
withBGApi { chatModel.controller.apiSetEncryptLocalFiles(enable) }
|
||||||
|
})
|
||||||
SettingsPreferenceItem(painterResource(MR.images.ic_image), stringResource(MR.strings.auto_accept_images), chatModel.controller.appPrefs.privacyAcceptImages)
|
SettingsPreferenceItem(painterResource(MR.images.ic_image), stringResource(MR.strings.auto_accept_images), chatModel.controller.appPrefs.privacyAcceptImages)
|
||||||
SettingsPreferenceItem(painterResource(MR.images.ic_travel_explore), stringResource(MR.strings.send_link_previews), chatModel.controller.appPrefs.privacyLinkPreviews)
|
SettingsPreferenceItem(painterResource(MR.images.ic_travel_explore), stringResource(MR.strings.send_link_previews), chatModel.controller.appPrefs.privacyLinkPreviews)
|
||||||
SettingsPreferenceItem(
|
SettingsPreferenceItem(
|
||||||
|
|
|
@ -113,6 +113,7 @@
|
||||||
<string name="error_xftp_test_server_auth">Server requires authorization to upload, check password</string>
|
<string name="error_xftp_test_server_auth">Server requires authorization to upload, check password</string>
|
||||||
<string name="error_smp_test_certificate">Possibly, certificate fingerprint in server address is incorrect</string>
|
<string name="error_smp_test_certificate">Possibly, certificate fingerprint in server address is incorrect</string>
|
||||||
<string name="error_setting_address">Error setting address</string>
|
<string name="error_setting_address">Error setting address</string>
|
||||||
|
<string name="error_alert_title">Error</string>
|
||||||
<string name="smp_server_test_connect">Connect</string>
|
<string name="smp_server_test_connect">Connect</string>
|
||||||
<string name="smp_server_test_disconnect">Disconnect</string>
|
<string name="smp_server_test_disconnect">Disconnect</string>
|
||||||
<string name="smp_server_test_create_queue">Create queue</string>
|
<string name="smp_server_test_create_queue">Create queue</string>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue