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

[legacy] adds new check for updated app and provides an in app upgrade experience #763

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions OpenHABCore/Sources/OpenHABCore/Util/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ public extension Endpoint {
)
}

static func appIds() -> Endpoint {
Endpoint(
baseURL: "https://myopenhab.org",
path: "/api/v1/appids",
queryItems: []
)
}

// swiftlint:disable:next function_parameter_count
static func chart(rootUrl: String, period: String?, type: OpenHABItem.ItemType?, service: String?, name: String?, legend: Bool?, theme: ChartStyle = .light, forceAsItem: Bool?) -> Endpoint {
let random = Int.random(in: 0 ..< 1000)
Expand Down
6 changes: 6 additions & 0 deletions OpenHABCore/Sources/OpenHABCore/Util/NetworkConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ public class NetworkConnection {
}
}

public static func appStoreIds(completionHandler: @escaping (DataResponse<Data, AFError>) -> Void) {
if let appIdsUrl = Endpoint.appIds().url {
load(from: appIdsUrl, completionHandler: completionHandler)
}
}

public static func sendState(item: CommItem, stateToSend state: String?) -> DataRequest? {
sendCommandOrState(item: item, commandToSend: state, state: true)
}
Expand Down
2 changes: 2 additions & 0 deletions OpenHABCore/Sources/OpenHABCore/Util/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public enum Preferences {
@UserDefault("sortSitemapsBy", defaultValue: 0) public static var sortSitemapsby: Int
@UserDefault("defaultMainUIPath", defaultValue: "") public static var defaultMainUIPath: String
@UserDefault("alwaysAllowWebRTC", defaultValue: false) public static var alwaysAllowWebRTC: Bool
@UserDefault("prompForUpgrade", defaultValue: true) public static var promptForUpgrade: Bool

// MARK: - Private

Expand All @@ -115,5 +116,6 @@ public extension Preferences {
Preferences.iconType = UserDefaults.standard.object(forKey: "iconType") as? Int ?? Preferences.iconType
Preferences.defaultSitemap = UserDefaults.standard.string(forKey: "defaultSitemap") ?? Preferences.defaultSitemap
Preferences.sendCrashReports = UserDefaults.standard.object(forKey: "sendCrashReports") as? Bool ?? Preferences.sendCrashReports
Preferences.promptForUpgrade = UserDefaults.standard.object(forKey: "prompForUpgrade") as? Bool ?? Preferences.promptForUpgrade
}
}
4 changes: 4 additions & 0 deletions openHAB.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
6557AF922C039D140094D0C8 /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = 6557AF912C039D140094D0C8 /* FirebaseMessaging */; };
656916D91FCB82BC00667B2A /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 656916D81FCB82BC00667B2A /* GoogleService-Info.plist */; };
6595667E28E0BE8E00E8A53B /* MulticastDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6595667D28E0BE8E00E8A53B /* MulticastDelegate.swift */; };
65ACEE322C1250DC007A0C56 /* LegacyNoticeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65ACEE312C1250DC007A0C56 /* LegacyNoticeViewController.swift */; };
933D7F0722E7015100621A03 /* OpenHABUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 933D7F0622E7015000621A03 /* OpenHABUITests.swift */; };
933D7F0F22E7030600621A03 /* SnapshotHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 933D7F0E22E7030600621A03 /* SnapshotHelper.swift */; };
935B484625342B8E00E44CF0 /* URL+Static.swift in Sources */ = {isa = PBXBuildFile; fileRef = 935B484525342B8E00E44CF0 /* URL+Static.swift */; };
Expand Down Expand Up @@ -194,6 +195,7 @@
6557AF8E2C0241C10094D0C8 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
656916D81FCB82BC00667B2A /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "GoogleService-Info.plist"; path = "openHAB/GoogleService-Info.plist"; sourceTree = SOURCE_ROOT; };
6595667D28E0BE8E00E8A53B /* MulticastDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MulticastDelegate.swift; sourceTree = "<group>"; };
65ACEE312C1250DC007A0C56 /* LegacyNoticeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegacyNoticeViewController.swift; sourceTree = "<group>"; };
931384B324F259BC00A73AB5 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; };
931384B424F259BD00A73AB5 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = "<group>"; };
931384BB24F2691B00A73AB5 /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -736,6 +738,7 @@
DFDF452E1932032B00A6E581 /* OpenHABLegalViewController.swift */,
DF06F1F518FE7A160011E7B9 /* OpenHABSelectionTableViewController.swift */,
A07EF79F2230C0A20040919F /* OpenHABClientCertificatesViewController.swift */,
65ACEE312C1250DC007A0C56 /* LegacyNoticeViewController.swift */,
DF4B84101886DA9900F34902 /* Widgets */,
DF4A02291CF3157B006C3456 /* Drawer */,
DFFD8FCE18EDBD30003B502A /* Util */,
Expand Down Expand Up @@ -1212,6 +1215,7 @@
files = (
93B7B33128018301009EB296 /* Intents.intentdefinition in Sources */,
DA7E1E4B2233986E002AEFD8 /* PlayerView.swift in Sources */,
65ACEE322C1250DC007A0C56 /* LegacyNoticeViewController.swift in Sources */,
DA7E1E492230227E002AEFD8 /* OpenHABTracker.swift in Sources */,
DF06F1F918FEA8420011E7B9 /* ColorPickerUITableViewCell.swift in Sources */,
65570A7D2476D16A00D524EA /* OpenHABWebViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Download_on_the_App_Store_Badge_US-UK_RGB_blk_092917.svg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions openHAB/LegacyNoticeViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) 2010-2024 Contributors to the openHAB project
//
// See the NOTICE file(s) distributed with this work for additional
// information.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0
//
// SPDX-License-Identifier: EPL-2.0

import OpenHABCore
import StoreKit
import UIKit

class LegacyNoticeViewController: UIViewController, SKStoreProductViewControllerDelegate {
@IBOutlet private var toggleSwitch: UISwitch!
@IBOutlet private var textView: UITextView!

var appData: OpenHABDataObject? {
AppDelegate.appDelegate.appData
}

override func viewDidLoad() {
super.viewDidLoad()
toggleSwitch.isOn = !Preferences.promptForUpgrade
textView.text = NSLocalizedString("upgrade_message_body", comment: "Click below to update")
}

@IBAction func imageClicked(_ sender: Any) {
if let updatedAppId = appData?.updatedAppId, !updatedAppId.isEmpty {
openStoreProductWithiTunesItemIdentifier(appData!.updatedAppId)
}
}

@IBAction func switchValueChanged(_ sender: UISwitch) {
Preferences.promptForUpgrade = !sender.isOn
}

func openStoreProductWithiTunesItemIdentifier(_ identifier: String) {
let storeViewController = SKStoreProductViewController()
storeViewController.delegate = self

let parameters = [SKStoreProductParameterITunesItemIdentifier: identifier]
storeViewController.loadProduct(withParameters: parameters) { [weak self] (loaded, _) in
if loaded {
self?.present(storeViewController, animated: true, completion: nil)
}
}
}

func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
viewController.dismiss(animated: true, completion: nil)
}
}
Loading
Loading