Skip to content

Commit

Permalink
Merge branch 'dev_2.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklandrin committed Jun 16, 2023
2 parents c04f268 + 1c37d78 commit 33ebbbc
Show file tree
Hide file tree
Showing 54 changed files with 2,148 additions and 259 deletions.
16 changes: 14 additions & 2 deletions Localization/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,17 @@
"Export" = "Export";
"The radio stations can be imported and exported as a Json file. The keys are \"name\" and \"url\"." = "The radio stations can be imported and exported as a Json file. The keys are \"name\" and \"url\".";
"Success" = "Success";


"Save commands failed." = "Save commands failed.";
"Can be saved after passing all tests" = "Can be saved after passing all tests";
"Save" = "Save";
"Evolution Editor" = "Evolution Editor";
"You can DIY switches or buttons here." = "You can DIY switches or buttons here.";
"Refresh" = "Refresh";
"Load Evolution list failed" = "Load Evolution list failed";
"Edit" = "Edit";
"Button" = "Button";
"Check status" = "Check status";
"Switch" = "Switch";
"Name:" = "Name:";
"True Condition" = "True Condition";
"Debug" = "Debug";
18 changes: 16 additions & 2 deletions Localization/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,25 @@
"Hide Windows" = "隐藏窗口";
"Disable" = "停用";
"Enable" = "启用";
"Turn off" = "开启";
"Turn on" = "关闭";
"Turn off" = "关闭";
"Turn on" = "开启";
"Running" = "执行中";
"TOOLS" = "工具";
"Import" = "导入";
"Export" = "导出";
"The radio stations can be imported and exported as a Json file. The keys are \"name\" and \"url\"." = "电台可以导入\/导出为一个Json文件。Key的名字为”name“和”url“。";
"Success" = "成功";
"Save commands failed." = "保存命令失败.";
"Can be saved after passing all tests" = "通过所有测试后可被保存";
"Save" = "保存";
"Evolution Editor" = "Evolution编辑器";
"You can DIY switches or buttons here." = "您可以制作自己的开关和按钮";
"Refresh" = "刷新";
"Load Evolution list failed" = "加载Evolution列表失败";
"Edit" = "编辑";
"Button" = "按钮";
"Check status" = "检查状态";
"Switch" = "开关";
"Name:" = "名称:";
"True Condition" = "开启条件";
"Debug" = "调试";
185 changes: 171 additions & 14 deletions OnlySwitch.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
"version" : "1.3.7"
}
},
{
"identity" : "combine-schedulers",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/combine-schedulers",
"state" : {
"revision" : "0625932976b3ae23949f6b816d13bd97f3b40b7c",
"version" : "0.10.0"
}
},
{
"identity" : "keyboardshortcuts",
"kind" : "remoteSourceControl",
Expand All @@ -36,6 +45,78 @@
"version" : "4.2.0"
}
},
{
"identity" : "swift-case-paths",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "fc45e7b2cfece9dd80b5a45e6469ffe67fe67984",
"version" : "0.14.1"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-clocks",
"state" : {
"revision" : "f9acfa1a45f4483fe0f2c434a74e6f68f865d12d",
"version" : "0.3.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version" : "1.0.4"
}
},
{
"identity" : "swift-composable-architecture",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-composable-architecture",
"state" : {
"revision" : "8b98ba40a2bc8e70579397f906ceb325e7c04b2f",
"version" : "0.54.0"
}
},
{
"identity" : "swift-custom-dump",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "505aa98716275fbd045d8f934fee3337c82ffbd3",
"version" : "0.10.3"
}
},
{
"identity" : "swift-dependencies",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "de1a984a71e51f6e488e98ce3652035563eb8acb",
"version" : "0.5.1"
}
},
{
"identity" : "swift-identified-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-identified-collections",
"state" : {
"revision" : "f52eee28bdc6065aa2f8424067e6f04c74bda6e6",
"version" : "0.7.1"
}
},
{
"identity" : "swiftui-navigation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swiftui-navigation",
"state" : {
"revision" : "db81007362f998654239021ca9308a264e59d3e2",
"version" : "0.7.2"
}
},
{
"identity" : "swiftui-webview",
"kind" : "remoteSourceControl",
Expand All @@ -44,6 +125,15 @@
"revision" : "f9be55089c020268760d626abbadd643a2b1ca4a",
"version" : "1.0.8"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "4af50b38daf0037cfbab15514a241224c3f62f98",
"version" : "0.8.5"
}
}
],
"version" : 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>OnlySwitchTests.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>4</integer>
<integer>2</integer>
</dict>
<key>Playground (Playground) 1.xcscheme</key>
<dict>
Expand Down
121 changes: 121 additions & 0 deletions OnlySwitch/CoreData/EvolutionCommandEntity+Fetch.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//
// EvolutionCommandEntity+Fetch.swift
// OnlySwitch
//
// Created by Jacklandrin on 2023/6/4.
//

import CoreData
import Foundation

extension EvolutionCommandEntity {
static var defaultFetchRequest:NSFetchRequest<EvolutionCommandEntity> {
let request:NSFetchRequest<EvolutionCommandEntity> = EvolutionCommandEntity.fetchRequest()
request.sortDescriptors = [NSSortDescriptor(keyPath: \EvolutionCommandEntity.timestamp, ascending: true)]
print("fetched the evolution command")
return request
}

static func fetchResult() throws -> [EvolutionCommandEntity] {
try PersistenceController
.shared
.container
.viewContext
.fetch(EvolutionCommandEntity.defaultFetchRequest)
}

static func fetchRequest(by id: UUID) throws -> EvolutionCommandEntity? {
let predicate = NSPredicate(
format: "%K = %@", "id" , "\(id)"
)

let request = EvolutionCommandEntity.fetchRequest()
request.sortDescriptors = [NSSortDescriptor(keyPath: \EvolutionCommandEntity.timestamp, ascending: true)]
request.predicate = predicate

return try PersistenceController
.shared
.container
.viewContext
.fetch(request)
.first
}

static func addItem(item: EvolutionItem) throws {
let context = PersistenceController
.shared
.container
.viewContext

let entity = try EvolutionCommandEntity.fetchRequest(by: item.id) ?? EvolutionCommandEntity(context: context)

if item.controlType == .Button {
guard
let singleCommand = item.singleCommand?.commandString,
!singleCommand.isEmpty,
let singleCommandTypeStr = item.singleCommand?.executeType.rawValue,
item.singleCommand?.debugStatus == .success else {
context.reset()
throw EvolutionError.wrongCommand
}
entity.singleCommand = singleCommand
entity.singleCommandType = singleCommandTypeStr
} else {
guard
let onCommand = item.onCommand?.commandString,
!onCommand.isEmpty,
let onCommandTypeStr = item.onCommand?.executeType.rawValue,
item.onCommand?.debugStatus == .success else {
context.reset()
throw EvolutionError.wrongCommand
}
entity.turnOnCommand = onCommand
entity.turnOnCommandType = onCommandTypeStr

guard
let offCommand = item.offCommand?.commandString,
!offCommand.isEmpty,
let offCommandTypeStr = item.offCommand?.executeType.rawValue,
item.offCommand?.debugStatus == .success else {
context.reset()
throw EvolutionError.wrongCommand
}

entity.turnOffCommand = offCommand
entity.turnOffCommandType = offCommandTypeStr

guard
let statusCommand = item.statusCommand?.commandString,
!statusCommand.isEmpty,
let statusCommandTypeStr = item.statusCommand?.executeType.rawValue,
let trueCondition = item.statusCommand?.trueCondition else {
context.reset()
throw EvolutionError.wrongCommand
}
entity.statusCommand = statusCommand
entity.statusCommandType = statusCommandTypeStr
entity.trueCondition = trueCondition
}

entity.name = item.name
entity.itemType = item.controlType.rawValue
entity.timestamp = Date()
entity.id = item.id


try context.save()
}

static func removeItem(by id: UUID) throws {
let context = PersistenceController
.shared
.container
.viewContext

guard let entity = try fetchRequest(by: id) else {
throw EvolutionError.deleteFailed
}

context.delete(entity)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21754" systemVersion="22F66" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
<entity name="EvolutionCommandEntity" representedClassName="EvolutionCommandEntity" syncable="YES" codeGenerationType="class">
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="itemType" optional="YES" attributeType="String"/>
<attribute name="name" optional="YES" attributeType="String"/>
<attribute name="singleCommand" optional="YES" attributeType="String"/>
<attribute name="singleCommandType" optional="YES" attributeType="String"/>
<attribute name="statusCommand" optional="YES" attributeType="String"/>
<attribute name="statusCommandType" optional="YES" attributeType="String"/>
<attribute name="timestamp" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="trueCondition" optional="YES" attributeType="String"/>
<attribute name="turnOffCommand" optional="YES" attributeType="String"/>
<attribute name="turnOffCommandType" optional="YES" attributeType="String"/>
<attribute name="turnOnCommand" optional="YES" attributeType="String"/>
<attribute name="turnOnCommandType" optional="YES" attributeType="String"/>
</entity>
<entity name="RadioStations" representedClassName="RadioStations" syncable="YES" codeGenerationType="class">
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="timestamp" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="title" optional="YES" attributeType="String"/>
<attribute name="url" optional="YES" attributeType="String"/>
</entity>
</model>
49 changes: 49 additions & 0 deletions OnlySwitch/CoreData/Persistence.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Persistence.swift
// Test
//
// Created by Jacklandrin on 2021/12/9.
//

import CoreData

struct PersistenceController {
static let shared = PersistenceController()

let container: NSPersistentCloudKitContainer

init(inMemory: Bool = false) {
container = NSPersistentCloudKitContainer(name: "OnlySwitch")
if inMemory {
container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
}
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
// Replace this implementation with code to handle the error appropriately.
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

/*
Typical reasons for an error here include:
* The parent directory does not exist, cannot be created, or disallows writing.
* The persistent store is not accessible, due to permissions or data protection when the device is locked.
* The device is out of space.
* The store could not be migrated to the current model version.
Check the error message to determine what the actual problem was.
*/
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
}

func saveContext() {
let context = self.container.viewContext
if context.hasChanges {
do {
try context.save()
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
}
}
}
Loading

0 comments on commit 33ebbbc

Please sign in to comment.