Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watchkit network tracker and more #843

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions OpenHABCore/Sources/OpenHABCore/Util/NetworkTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public final class NetworkTracker: ObservableObject {
public func startTracking(connectionConfigurations: [ConnectionConfiguration], username: String, password: String, alwaysSendBasicAuth: Bool) {
self.connectionConfigurations = connectionConfigurations
httpClient = HTTPClient(username: username, password: password, alwaysSendBasicAuth: alwaysSendBasicAuth)
setActiveConnection(nil)
attemptConnection()
}

Expand Down
4 changes: 0 additions & 4 deletions openHAB.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
DAA42BA821DC97E000244B2A /* NotificationTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAA42BA721DC97DF00244B2A /* NotificationTableViewCell.swift */; };
DAA42BAA21DC983B00244B2A /* VideoUITableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAA42BA921DC983B00244B2A /* VideoUITableViewCell.swift */; };
DAA42BAC21DC984A00244B2A /* WebUITableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAA42BAB21DC984A00244B2A /* WebUITableViewCell.swift */; };
DAAC30862CBBF0230041927F /* OpenHABWatchTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAAC30852CBBF0230041927F /* OpenHABWatchTracker.swift */; };
DAAC30872CBBF0420041927F /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA0775262346705F0086C685 /* ContentView.swift */; };
DAC65FC7236EDF3900F4501E /* SpinnerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAC65FC6236EDF3900F4501E /* SpinnerViewController.swift */; };
DAC6608D236F771600F4501E /* PreferencesSwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAC6608C236F771600F4501E /* PreferencesSwiftUIView.swift */; };
Expand Down Expand Up @@ -413,7 +412,6 @@
DAA42BA721DC97DF00244B2A /* NotificationTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationTableViewCell.swift; sourceTree = "<group>"; };
DAA42BA921DC983B00244B2A /* VideoUITableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VideoUITableViewCell.swift; sourceTree = "<group>"; };
DAA42BAB21DC984A00244B2A /* WebUITableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebUITableViewCell.swift; sourceTree = "<group>"; };
DAAC30852CBBF0230041927F /* OpenHABWatchTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenHABWatchTracker.swift; sourceTree = "<group>"; };
DAC65FC6236EDF3900F4501E /* SpinnerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpinnerViewController.swift; sourceTree = "<group>"; };
DAC6608B236F6F4200F4501E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
DAC6608C236F771600F4501E /* PreferencesSwiftUIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesSwiftUIView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -582,7 +580,6 @@
isa = PBXGroup;
children = (
DA0776EF234788010086C685 /* UserData.swift */,
DAAC30852CBBF0230041927F /* OpenHABWatchTracker.swift */,
);
path = Domain;
sourceTree = "<group>";
Expand Down Expand Up @@ -1487,7 +1484,6 @@
DA50C7BD2B0A51BD0009F716 /* SliderWithSwitchSupportRow.swift in Sources */,
DAF457A623DB9CE00018B495 /* SetpointRow.swift in Sources */,
DAA070932B5181210060BB0E /* OpenHABImageDownloaderOperation.swift in Sources */,
DAAC30862CBBF0230041927F /* OpenHABWatchTracker.swift in Sources */,
DAF4581823DC4A050018B495 /* ImageRow.swift in Sources */,
9350F17923814FAC00054BA8 /* ObservableOpenHABWidget.swift in Sources */,
DA07752F2346705F0086C685 /* NotificationView.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions openHAB/OpenHABSitemapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ class OpenHABSitemapViewController: OpenHABViewController, GenericUITableViewCel
case .notConnected:
os_log("Tracking error", log: .viewCycle, type: .info)
self.showPopupMessage(seconds: 60, title: NSLocalizedString("error", comment: ""), message: NSLocalizedString("network_not_available", comment: ""), theme: .error)
case .connected:
self.hidePopupMessages()
case _:
break
}
Expand Down
36 changes: 36 additions & 0 deletions openHAB/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,16 @@ struct SettingsView: View {
@State var settingsSortSitemapsBy: SortSitemapsOrder = .label
@State var settingsDefaultMainUIPath = ""
@State var settingsAlwaysAllowWebRTC = true
@State var settingsSitemapForWatch = ""

@State private var showingCacheAlert = false
@State private var showCrashReportingAlert = false
@State private var showUselastPathAlert = false

@State private var hasBeenLoaded = false

@State private var sitemaps: [OpenHABSitemap] = []

@Environment(\.dismiss) private var dismiss

var appData: OpenHABDataObject? {
Expand Down Expand Up @@ -154,6 +157,7 @@ struct SettingsView: View {
// Setting .onAppear of view required here because onAppear of entire view is run after onChange is active
// when migrating to iOS17 this
settingsSendCrashReports = Preferences.sendCrashReports
loadSitemaps()
hasBeenLoaded = true
}
.onChange(of: settingsSendCrashReports) { newValue in
Expand Down Expand Up @@ -273,6 +277,14 @@ struct SettingsView: View {
} label: {
Text("Sort sitemaps by")
}

Picker(selection: $settingsSitemapForWatch) {
ForEach(sitemaps, id: \.name) { sitemap in
Text(sitemap.name).tag(sitemap as OpenHABSitemap?)
}
} label: {
Text("Sitemap For Apple Watch")
}
}

Section(header: Text(LocalizedStringKey("about_settings"))) {
Expand Down Expand Up @@ -344,6 +356,7 @@ struct SettingsView: View {
settingsSortSitemapsBy = SortSitemapsOrder(rawValue: Preferences.sortSitemapsby) ?? .label
settingsDefaultMainUIPath = Preferences.defaultMainUIPath
settingsAlwaysAllowWebRTC = Preferences.alwaysAllowWebRTC
settingsSitemapForWatch = Preferences.sitemapForWatch
}

func saveSettings() {
Expand All @@ -361,10 +374,33 @@ struct SettingsView: View {
Preferences.sortSitemapsby = settingsSortSitemapsBy.rawValue
Preferences.defaultMainUIPath = settingsDefaultMainUIPath
Preferences.alwaysAllowWebRTC = settingsAlwaysAllowWebRTC
Preferences.sitemapForWatch = settingsSitemapForWatch
WatchMessageService.singleton.syncPreferencesToWatch()
Crashlytics.crashlytics().setCrashlyticsCollectionEnabled(settingsSendCrashReports)
logger.debug("setCrashlyticsCollectionEnabled to \(settingsSendCrashReports)")
}

private func loadSitemaps() {
NetworkConnection.sitemaps(openHABRootUrl: appData?.openHABRootUrl ?? "") { response in
switch response.result {
case let .success(data):
os_log("Sitemap response", log: .viewCycle, type: .info)

sitemaps = deriveSitemaps(data)

if sitemaps.last?.name == "_default", sitemaps.count > 1 {
sitemaps = Array(sitemaps.dropLast())
}

switch SortSitemapsOrder(rawValue: Preferences.sortSitemapsby) ?? .label {
case .label: sitemaps.sort { $0.label < $1.label }
case .name: sitemaps.sort { $0.name < $1.name }
}
case let .failure(error):
os_log("%{PUBLIC}@", log: .default, type: .error, error.localizedDescription)
}
}
}
}

extension UIApplication {
Expand Down
Loading