Skip to content

Commit

Permalink
Migration for snippets shortcut. Refs #1755
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Jul 18, 2023
1 parent 07053a9 commit 8617749
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Blink.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -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 */; };
Expand Down Expand Up @@ -1095,6 +1096,7 @@
D2AD9ADD22DB80DE00861F66 /* SessionRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionRegistry.swift; sourceTree = "<group>"; };
D2AE682728D05FD0003E4338 /* WebAuthnKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebAuthnKey.swift; sourceTree = "<group>"; };
D2B0BD1B2720312C00485854 /* GesturesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GesturesView.swift; sourceTree = "<group>"; };
D2B1DEB42A669342001C6D3B /* 1620Migration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = 1620Migration.swift; sourceTree = "<group>"; };
D2B1F8DC23265A0600634D67 /* CommandsHUDView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandsHUDView.swift; sourceTree = "<group>"; };
D2B1F8DE23265A4700634D67 /* CommandControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandControl.swift; sourceTree = "<group>"; };
D2B788842949C53100F19E4F /* BuildView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuildView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1729,6 +1731,7 @@
isa = PBXGroup;
children = (
BD9EA1FD271A148700874007 /* 1400Migration.swift */,
D2B1DEB42A669342001C6D3B /* 1620Migration.swift */,
BD9EA1F9271A148700874007 /* Migrator.swift */,
);
path = Migrator;
Expand Down Expand Up @@ -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 */,
Expand Down
4 changes: 4 additions & 0 deletions Blink/KBTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ class KBTracker: NSObject {
return data
}

func kbAlreadyConfigured() -> Bool {
_loadKBConfigData() != nil
}

func loadConfig() -> KBConfig {
guard
let data = _loadKBConfigData(),
Expand Down
64 changes: 64 additions & 0 deletions Blink/Migrator/1620Migration.swift
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//
// 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
// <http://www.github.com/blinksh/blink>.
//
////////////////////////////////////////////////////////////////////////////////

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)

}

}
2 changes: 1 addition & 1 deletion Blink/Migrator/Migrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
6 changes: 5 additions & 1 deletion KB/Native/Model/KeyShortcut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -156,7 +160,7 @@ class KeyShortcut: ObservableObject, Codable, Identifiable {
KeyShortcut(.zoomReset, .command, "="),

KeyShortcut(.configShow, .command, ","),
KeyShortcut(.snippetsShow, [.command, .shift], ","),
Self.snippetsShowShortcut
]
}
}

0 comments on commit 8617749

Please sign in to comment.