Skip to content

Commit

Permalink
2.3.3
Browse files Browse the repository at this point in the history
macOS 14 compatibility issues
  • Loading branch information
ZzzM committed Jan 4, 2024
1 parent 519c1d3 commit 3c0facc
Show file tree
Hide file tree
Showing 25 changed files with 150 additions and 83 deletions.
2 changes: 2 additions & 0 deletions CalendarX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = CalendarX/Info.plist;
INFOPLIST_KEY_LSUIElement = YES;
INFOPLIST_KEY_NSCalendarsUsageDescription = "Used to display calendar events";
INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2020 ZzzM. All rights reserved.";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -748,6 +749,7 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = CalendarX/Info.plist;
INFOPLIST_KEY_LSUIElement = YES;
INFOPLIST_KEY_NSCalendarsUsageDescription = "Used to display calendar events";
INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2020 ZzzM. All rights reserved.";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
2 changes: 2 additions & 0 deletions CalendarX/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSCalendarsFullAccessUsageDescription</key>
<string>Used to display calendar events</string>
<key>NSUserActivityTypes</key>
<array>
<string>WidgetConfigurationIntent</string>
Expand Down
2 changes: 1 addition & 1 deletion CalendarX/Module/Calender/DateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct DateView: View {
TitleView {
Text(appDate.date, style: .date)
} leftItems: {
ScacleImageButton(image: .backward, action: Router.backMain)
ScacleImageButton(image: .backward, action: Router.back)
} rightItems: {
EmptyView()
}
Expand Down
12 changes: 12 additions & 0 deletions CalendarX/Module/Calender/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,25 @@ struct MainView: View {

HStack {
MonthYearPicker(date: $viewModel.date, colorScheme: viewModel.colorScheme, tint: viewModel.tint)

Spacer()
Group {
Button(action: viewModel.lastMonth) {}.keyboardShortcut(.leftArrow, modifiers: [])
Button(action: viewModel.reset) {}.keyboardShortcut(.space, modifiers: [])
Button(action: viewModel.nextMonth) {}.keyboardShortcut(.rightArrow, modifiers: [])
Button(action: viewModel.lastYear) {}.keyboardShortcut(.upArrow, modifiers: [])
Button(action: viewModel.nextYear) {}.keyboardShortcut(.downArrow, modifiers: [])
}
.frame(maxWidth: 1)
.opacity(.zero)

ScacleImageButton(image: .leftArrow, action: viewModel.lastMonth)
.frame(width: .buttonWidth)
ScacleImageButton(image: .circle, action: viewModel.reset)
.frame(width: .buttonWidth)
ScacleImageButton(image: .rightArrow, action: viewModel.nextMonth)
.frame(width: .buttonWidth)

}

}
Expand Down
24 changes: 19 additions & 5 deletions CalendarX/Module/Calender/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ struct RootView: View {
@StateObject
private var settingsVM = SettingsViewModel()


var body: some View {

ZStack {
Color.appBackground.padding(.top, -15)
content.padding()

Group {
rootView
detailView
}
.padding()

AlertView(alert: alert).zIndex(1)
}
.appForeground(.appPrimary)
Expand All @@ -39,16 +44,25 @@ struct RootView: View {
}

@ViewBuilder
private var content: some View {
private var rootView: some View {
if router.isCalendar {
MainView(viewModel: mainVM)
} else {
SettingsView(viewModel: settingsVM)
}
}


@ViewBuilder
private var detailView: some View {
switch router.path {
case .main: MainView(viewModel: mainVM)
case .settings: SettingsView(viewModel: settingsVM)
case .date(let appDate): DateView(appDate: appDate).fullScreenCover()
case .recommendations: RecommendationsView().fullScreenCover()
case .menubarSettings: MenubarSettingsView().fullScreenCover()
case .appearanceSettings: AppearanceSettingsView(viewModel: settingsVM).fullScreenCover()
case .calendarSettings: CalendarSettingsView().fullScreenCover()
case .about: AboutView().fullScreenCover()
default: EmptyView()
}
}

Expand Down
2 changes: 1 addition & 1 deletion CalendarX/Module/Settings/AboutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct AboutView: View {
TitleView {
Text(L10n.Settings.about)
} leftItems: {
ScacleImageButton(image: .backward, action: Router.backSettings)
ScacleImageButton(image: .backward, action: Router.back)
} rightItems: {
EmptyView()
}
Expand Down
2 changes: 1 addition & 1 deletion CalendarX/Module/Settings/AppearanceSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct AppearanceSettingsView: View {
TitleView {
Text(L10n.Settings.appearance)
} leftItems: {
ScacleImageButton(image: .backward, action: Router.backSettings)
ScacleImageButton(image: .backward, action: Router.back)
} rightItems: {
EmptyView()
}
Expand Down
2 changes: 1 addition & 1 deletion CalendarX/Module/Settings/CalendarSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct CalendarSettingsView: View {
TitleView {
Text(L10n.Settings.calendar)
} leftItems: {
ScacleImageButton(image: .backward, action: Router.backSettings)
ScacleImageButton(image: .backward, action: Router.back)
} rightItems: {
EmptyView()
}
Expand Down
2 changes: 1 addition & 1 deletion CalendarX/Module/Settings/MenuBarSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct MenubarSettingsView: View {
TitleView {
Text(L10n.Settings.menubarStyle)
} leftItems: {
ScacleImageButton(image: .backward, action: Router.backSettings)
ScacleImageButton(image: .backward, action: Router.back)
} rightItems: {
if viewModel.canSave {
ScacleImageButton(image: .save, action: viewModel.save)
Expand Down
2 changes: 1 addition & 1 deletion CalendarX/Module/Settings/RecommendationsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct RecommendationsView: View {
TitleView {
Text(L10n.Settings.recommendations)
} leftItems: {
ScacleImageButton(image: .backward, action: Router.backSettings)
ScacleImageButton(image: .backward, action: Router.back)
} rightItems: {
EmptyView()
}
Expand Down
2 changes: 1 addition & 1 deletion CalendarX/Module/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct SettingsView: View {

TitleView {
Text( L10n.Settings.title).onTapGesture {
Router.backMain()
Router.back()
}
} leftItems: {
EmptyView()
Expand Down
10 changes: 9 additions & 1 deletion CalendarX/ViewModel/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ class MainViewModel: ObservableObject {
func nextMonth() {
date.nextMonth()
}


func lastYear() {
date.lastYear()
}

func nextYear() {
date.nextYear()
}

func reset() {
date = Date()
}
Expand Down
2 changes: 1 addition & 1 deletion CalendarX/ViewModel/MenubarViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class MenubarViewModel: ObservableObject {

pref.style = style

Router.backSettings()
Router.back()

NotificationCenter.default.post(name: .titleStyleDidChanged, object: .none)
}
Expand Down
20 changes: 12 additions & 8 deletions CalendarX/ViewModel/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ class Router: ObservableObject {
static let shared = Router()

enum Path {
case main, date(AppDate), settings,
recommendations, menubarSettings, appearanceSettings, calendarSettings, about
case date(AppDate), recommendations, menubarSettings, appearanceSettings, calendarSettings, about, unknown
}

@Published
var path = Path.main

var path = Path.unknown

@Published
var isCalendar = true

private static func to(_ path: Path, animated: Bool = true) {
if animated {
Expand All @@ -30,21 +31,24 @@ class Router: ObservableObject {
}

static func to(_ isRightClicked: Bool) {
to(isRightClicked ? .settings : .main, animated: false)
to(.unknown, animated: false)
shared.isCalendar = !isRightClicked
}

static func back() {
to(.unknown)
}
}

extension Router {

static func backMain() { to(.main) }


static func toDate(_ appDate: AppDate) { to(.date(appDate)) }
}

extension Router {

static func backSettings() { to(.settings) }

static func toRecommendations() { to(.recommendations) }

static func toMenubarSettings() { to(.menubarSettings) }
Expand Down
2 changes: 2 additions & 0 deletions CalendarX/en.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@

*/
"NSCalendarsUsageDescription" = "Used to display calendar events";
"NSCalendarsFullAccessUsageDescription" = "Used to display calendar events";

1 change: 1 addition & 0 deletions CalendarX/zh-Hans.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

*/
"NSCalendarsUsageDescription" = "用于显示日历事件";
"NSCalendarsFullAccessUsageDescription" = "用于显示日历事件";
20 changes: 10 additions & 10 deletions CalendarXShared/Sources/Constant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public extension CGFloat {
}

extension Bundle {
public static let apps: [AppInfo] = module.json2Object(from: "apps") ?? []
static let tiaoxiu: [String: [String: AppDateState]] = module.json2KeyValue(from: "tiaoxiu")
static let solarAF = module.json2AllFestivals(from: "solarAF") // Contains solarPF
static let weekAF = module.json2AllFestivals(from: "weekAF")
static let weekSF = module.json2Festival(from: "weekSF")
static let solarPF = module.json2Festival(from: "solarPF")
static let weekPF = module.json2Festival(from: "weekPF")
static let lunarPF = module.json2Festival(from: "lunarPF")
static let chuxi = module.json2Festival(from: "chuxi")
static let terms = module.json2AllFestivals(from: "terms")
public static let apps = PatternA.toObject(from: "apps")
static let tiaoxiu = PatternB.toObject(from: "tiaoxiu") // [String: [String: AppDateState]] = module.json2KeyValue(from: "tiaoxiu")
static let solarAF = PatternC.toObject(from: "solarAF") // module.json2AllFestivals(from: "solarAF") // Contains solarPF
static let weekAF = PatternC.toObject(from: "weekAF") // module.json2AllFestivals(from: "weekAF")
static let weekSF = PatternD.toObject(from: "weekSF") //module.json2Festival(from: "weekSF")
static let solarPF = PatternD.toObject(from: "solarPF") //module.json2Festival(from: "solarPF")
static let weekPF = PatternD.toObject(from: "weekPF") // module.json2Festival(from: "weekPF")
static let lunarPF = PatternD.toObject(from: "lunarPF") //module.json2Festival(from: "lunarPF")
static let chuxi = PatternD.toObject(from: "chuxi") //module.json2Festival(from: "chuxi")
static let terms = PatternC.toObject(from: "terms") //module.json2AllFestivals(from: "terms")
}

public extension UserDefaults {
Expand Down
8 changes: 0 additions & 8 deletions CalendarXShared/Sources/Extension/AppKit+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,6 @@ public extension String {

}

public extension String {
func toObject<T: Decodable>(_ type: T.Type) -> T? {
guard let data = data(using: .utf8) else { return .none }
return try? JSONDecoder().decode(type, from: data)
}
}


public extension Binding where Value == String {
func max(_ limit: Int = 30) -> Self {
if self.wrappedValue.count > limit {
Expand Down
51 changes: 31 additions & 20 deletions CalendarXShared/Sources/Extension/Bundle+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,40 @@

import Foundation

public extension Bundle {
func json2KeyValue<T: Decodable>(from resource: String) -> [String: T] {
guard let url = url(forResource: resource, withExtension: "json"),
let data = try? Data(contentsOf: url),
let dict = try? JSONDecoder().decode([String: T].self, from: data) else {
return [:]
}
return dict
}
func json2Object<T: Decodable>(from resource: String) -> T? {
guard let url = url(forResource: resource, withExtension: "json"),
protocol JSONDecodable {
associatedtype Response: Decodable
static var empty: Response { get }
}

extension JSONDecodable {
static func toObject(from resource: String) -> Response {
guard let url = Bundle.module.url(forResource: resource, withExtension: "json"),
let data = try? Data(contentsOf: url),
let object = try? JSONDecoder().decode(T.self, from: data) else {
return .none
let object = try? JSONDecoder().decode(Response.self, from: data) else {
return empty
}
return object
}

func json2Festival(from resource: String) -> [String: String] {
json2KeyValue(from: resource)
}
func json2AllFestivals(from resource: String) -> [String: [String]] {
json2KeyValue(from: resource)
}
}

public struct PatternA: JSONDecodable {
public typealias Response = [AppInfo]
static var empty: Response { [] }
}

struct PatternB: JSONDecodable {
typealias Response = [String: [String: AppDateState]]
static var empty: Response { [:] }
}

struct PatternC: JSONDecodable {
typealias Response = [String: [String]]
static var empty: Response { [:] }
}

struct PatternD: JSONDecodable {
typealias Response = [String: String]
static var empty: Response { [:] }
}


8 changes: 8 additions & 0 deletions CalendarXShared/Sources/Extension/Date+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ public extension Date {
added(component: .month, value: 1)
}

mutating func lastYear() {
added(component: .year, value: -1)
}

mutating func nextYear() {
added(component: .year, value: 1)
}

var startOfTomorrow: Date {
let startOfDay = Calendar.gregorian.startOfDay(for: self)
return Calendar.gregorian.date(byAdding: .day, value: 1, to: startOfDay) ?? self
Expand Down
5 changes: 2 additions & 3 deletions CalendarXShared/Sources/Extension/View+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import SwiftUI

import WidgetKit

public extension View {

Expand All @@ -18,10 +18,9 @@ public extension View {
foregroundColor(color)
}
}

}



struct TintModifier: ViewModifier {

let tint: Color
Expand Down
Loading

0 comments on commit 3c0facc

Please sign in to comment.