From 86177495c89a28a55494e819cef34a6d7d1ef908 Mon Sep 17 00:00:00 2001 From: Yury Korolev Date: Tue, 18 Jul 2023 13:12:07 +0300 Subject: [PATCH] Migration for snippets shortcut. Refs #1755 --- Blink.xcodeproj/project.pbxproj | 6 ++- Blink/KBTracker.swift | 4 ++ Blink/Migrator/1620Migration.swift | 64 ++++++++++++++++++++++++++++++ Blink/Migrator/Migrator.swift | 2 +- KB/Native/Model/KeyShortcut.swift | 6 ++- 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 Blink/Migrator/1620Migration.swift diff --git a/Blink.xcodeproj/project.pbxproj b/Blink.xcodeproj/project.pbxproj index 2caf026f4..2ce827cdb 100644 --- a/Blink.xcodeproj/project.pbxproj +++ b/Blink.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 52; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -384,6 +384,7 @@ D2AE682828D05FD0003E4338 /* WebAuthnKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2AE682728D05FD0003E4338 /* WebAuthnKey.swift */; }; D2AE682A28D06076003E4338 /* SwiftCBOR in Frameworks */ = {isa = PBXBuildFile; productRef = D2AE682928D06076003E4338 /* SwiftCBOR */; }; D2B0BD1C2720312C00485854 /* GesturesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2B0BD1B2720312C00485854 /* GesturesView.swift */; }; + D2B1DEB52A669342001C6D3B /* 1620Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2B1DEB42A669342001C6D3B /* 1620Migration.swift */; }; D2B1F8DD23265A0600634D67 /* CommandsHUDView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2B1F8DC23265A0600634D67 /* CommandsHUDView.swift */; }; D2B1F8DF23265A4700634D67 /* CommandControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2B1F8DE23265A4700634D67 /* CommandControl.swift */; }; D2B788852949C53100F19E4F /* BuildView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2B788842949C53100F19E4F /* BuildView.swift */; }; @@ -1095,6 +1096,7 @@ D2AD9ADD22DB80DE00861F66 /* SessionRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionRegistry.swift; sourceTree = ""; }; D2AE682728D05FD0003E4338 /* WebAuthnKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebAuthnKey.swift; sourceTree = ""; }; D2B0BD1B2720312C00485854 /* GesturesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GesturesView.swift; sourceTree = ""; }; + D2B1DEB42A669342001C6D3B /* 1620Migration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = 1620Migration.swift; sourceTree = ""; }; D2B1F8DC23265A0600634D67 /* CommandsHUDView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandsHUDView.swift; sourceTree = ""; }; D2B1F8DE23265A4700634D67 /* CommandControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandControl.swift; sourceTree = ""; }; D2B788842949C53100F19E4F /* BuildView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuildView.swift; sourceTree = ""; }; @@ -1729,6 +1731,7 @@ isa = PBXGroup; children = ( BD9EA1FD271A148700874007 /* 1400Migration.swift */, + D2B1DEB42A669342001C6D3B /* 1620Migration.swift */, BD9EA1F9271A148700874007 /* Migrator.swift */, ); path = Migrator; @@ -3315,6 +3318,7 @@ BD1758AC26EA8C5400AEC545 /* MenuController.swift in Sources */, 074F30791D062A2800A73445 /* main.m in Sources */, D2A5221E230D279B0010AC04 /* SmarterTermInput.swift in Sources */, + D2B1DEB52A669342001C6D3B /* 1620Migration.swift in Sources */, D23D258823438B15002850CA /* UIColor.swift in Sources */, D2AD8E7627A2BAFA00DED28D /* Purchases.swift in Sources */, D2DC5D1329547DFD007E2B9D /* PipFaceCam.swift in Sources */, diff --git a/Blink/KBTracker.swift b/Blink/KBTracker.swift index afb5b84ab..99bbab229 100644 --- a/Blink/KBTracker.swift +++ b/Blink/KBTracker.swift @@ -161,6 +161,10 @@ class KBTracker: NSObject { return data } + func kbAlreadyConfigured() -> Bool { + _loadKBConfigData() != nil + } + func loadConfig() -> KBConfig { guard let data = _loadKBConfigData(), diff --git a/Blink/Migrator/1620Migration.swift b/Blink/Migrator/1620Migration.swift new file mode 100644 index 000000000..6e230c2ec --- /dev/null +++ b/Blink/Migrator/1620Migration.swift @@ -0,0 +1,64 @@ +////////////////////////////////////////////////////////////////////////////////// +// +// B L I N K +// +// Copyright (C) 2016-2019 Blink Mobile Shell Project +// +// This file is part of Blink. +// +// Blink is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Blink 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 for more details. +// +// You should have received a copy of the GNU General Public License +// along with Blink. If not, see . +// +// In addition, Blink is also subject to certain additional terms under +// GNU GPL version 3 section 7. +// +// You should have received a copy of these additional terms immediately +// following the terms and conditions of the GNU General Public License +// which accompanied the Blink Source Code. If not, see +// . +// +//////////////////////////////////////////////////////////////////////////////// + +import Foundation +import CoreData + + +class MigrationAddSnippetsShortcut: MigrationStep { + var version: Int { get { 1620 } } + + func execute() throws { + + guard KBTracker.shared.kbAlreadyConfigured() else { + // user still uses default configuration + return + } + + let cfg = KBTracker.shared.loadConfig() + let contains = cfg.shortcuts.contains { shortcut in + switch shortcut.action { + case KeyBindingAction.command(Command.snippetsShow): return true; + default: return false; + } + } + + if contains { + // user already configured snippets show action + return + } + + cfg.shortcuts.append(KeyShortcut.snippetsShowShortcut) + KBTracker.shared.saveAndApply(config: cfg) + + } + +} diff --git a/Blink/Migrator/Migrator.swift b/Blink/Migrator/Migrator.swift index 7031086e1..1c132ab85 100644 --- a/Blink/Migrator/Migrator.swift +++ b/Blink/Migrator/Migrator.swift @@ -35,7 +35,7 @@ import Foundation @objc class Migrator : NSObject { @objc static func perform() { - Self.perform(steps: [MigrationToAppGroup()]) + Self.perform(steps: [MigrationToAppGroup(), MigrationAddSnippetsShortcut()]) } static func perform(steps: [MigrationStep]) { diff --git a/KB/Native/Model/KeyShortcut.swift b/KB/Native/Model/KeyShortcut.swift index 19169178e..f4b516368 100644 --- a/KB/Native/Model/KeyShortcut.swift +++ b/KB/Native/Model/KeyShortcut.swift @@ -133,6 +133,10 @@ class KeyShortcut: ObservableObject, Codable, Identifiable { self.init(action: action, modifiers: modifiers, input: input) } + static var snippetsShowShortcut: KeyShortcut { + KeyShortcut(.snippetsShow, [.command, .shift], ",") + } + static var defaultList: [KeyShortcut] { [ KeyShortcut(.clipboardCopy, .command, "c"), @@ -156,7 +160,7 @@ class KeyShortcut: ObservableObject, Codable, Identifiable { KeyShortcut(.zoomReset, .command, "="), KeyShortcut(.configShow, .command, ","), - KeyShortcut(.snippetsShow, [.command, .shift], ","), + Self.snippetsShowShortcut ] } }