-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8abfc1
commit 78d3dba
Showing
15 changed files
with
299 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// NSImage.swift | ||
// | ||
// | ||
// Created by Kevin Hermawan on 09/01/24. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
public extension NSImage { | ||
func write(to url: URL) throws -> Void { | ||
guard let tiff = self.tiffRepresentation else { return } | ||
guard let bitmap = NSBitmapImageRep(data: tiff) else { return } | ||
guard let data = bitmap.representation(using: .png, properties: [:]) else { return } | ||
|
||
try data.write(to: url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/configuration/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// swift-tools-version: 5.9 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "SettingsModule", | ||
platforms: [.macOS(.v14)], | ||
products: [ | ||
.library( | ||
name: "SettingsModule", | ||
targets: ["SettingsModule"]), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/sindresorhus/Defaults.git", .upToNextMajor(from: "7.3.1")) | ||
], | ||
targets: [ | ||
.target( | ||
name: "SettingsModule", | ||
dependencies: ["Defaults"]), | ||
.testTarget( | ||
name: "SettingsModuleTests", | ||
dependencies: ["SettingsModule"]), | ||
] | ||
) |
17 changes: 17 additions & 0 deletions
17
SettingsModule/Sources/SettingsModule/Extensions/Defaults+Keys.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// Defaults+Keys.swift | ||
// | ||
// | ||
// Created by Kevin Hermawan on 09/01/24. | ||
// | ||
|
||
import Defaults | ||
import Foundation | ||
|
||
let fileManager = FileManager.default | ||
let homeDirectory = fileManager.homeDirectoryForCurrentUser | ||
|
||
public extension Defaults.Keys { | ||
static let autosaveEnabled = Key<Bool>("autosaveEnabled", default: true) | ||
static let autosaveLocation = Key<URL>("autosaveLocation", default: homeDirectory.appending(path: "Canvas")) | ||
} |
26 changes: 26 additions & 0 deletions
26
SettingsModule/Sources/SettingsModule/Managers/SettingsManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// SettingsManager.swift | ||
// | ||
// | ||
// Created by Kevin Hermawan on 09/01/24. | ||
// | ||
|
||
import Defaults | ||
import Foundation | ||
|
||
@Observable | ||
public final class SettingsManager { | ||
public var autosaveEnabled: Bool = Defaults[.autosaveEnabled] { | ||
didSet { | ||
Defaults[.autosaveEnabled] = autosaveEnabled | ||
} | ||
} | ||
|
||
public var autosaveLocation: URL = Defaults[.autosaveLocation] { | ||
didSet { | ||
Defaults[.autosaveLocation] = autosaveLocation | ||
} | ||
} | ||
|
||
public init() {} | ||
} |
Oops, something went wrong.