Skip to content

Commit d4acbfe

Browse files
committed
fixes to UI offline caching
1 parent 2309855 commit d4acbfe

7 files changed

Lines changed: 52 additions & 25 deletions

File tree

native/app/Embedded/ui.zip

1.07 KB
Binary file not shown.

native/app/Source/Helpers/Networking.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ import Reachability
1111

1212
class Networking {
1313
static func isReachable (_ host: String, _ callback: @escaping (Bool) -> Void) {
14-
let ping = try! SwiftyPing(
14+
if let ping = try? SwiftyPing(
1515
host: host,
1616
configuration: PingConfiguration(interval: 0.1, with: 5),
1717
queue: DispatchQueue.global()
18-
)
19-
ping.observer = { (response) in
20-
callback(response.error == nil)
18+
) {
19+
ping.observer = { (response) in
20+
callback(response.error == nil)
21+
ping.stopPinging()
22+
}
23+
ping.startPinging()
24+
} else {
25+
callback(false)
2126
}
22-
ping.targetCount = 1
23-
ping.startPinging()
2427
}
2528

2629
static func tcpPortIsAvailable(_ port: UInt) -> Bool {

native/app/Source/UI/UI.swift

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,33 @@ extension UIMode {
2929

3030
class UI: StoreSubscriber {
3131
static var domain = Constants.UI_ENDPOINT_URL.host!
32-
static func unarchiveLocal () {
32+
33+
static func unarchiveZip () {
3334
// Unpack Archive
3435
let file = FileManager.default
35-
36-
if !file.fileExists(atPath: appSupportUIZipPath.path) {
37-
Console.log("\(appSupportUIZipPath.path) doesnt exist")
38-
let bundleUIZipPath = Bundle.main.url(forResource: "ui", withExtension: "zip")!
39-
try! file.copyItem(at: bundleUIZipPath, to: appSupportUIZipPath)
40-
}
4136

42-
try! Zip.unzipFile(appSupportUIZipPath, destination: localPath, overwrite: true, password: nil) // Unzip
37+
if file.fileExists(atPath: remoteZipPath.path) {
38+
try! Zip.unzipFile(remoteZipPath, destination: localPath, overwrite: true, password: nil) // Unzip
39+
} else {
40+
if !file.fileExists(atPath: localZipPath.path) {
41+
Console.log("\(localZipPath.path) doesnt exist")
42+
let bundleUIZipPath = Bundle.main.url(forResource: "ui", withExtension: "zip")!
43+
try! file.copyItem(at: bundleUIZipPath, to: localZipPath)
44+
}
45+
try! Zip.unzipFile(localZipPath, destination: localPath, overwrite: true, password: nil) // Unzip
46+
}
47+
}
48+
49+
static var localZipPath: URL {
50+
return Application.supportPath.appendingPathComponent(
51+
"ui-\(Application.version) (Local).zip",
52+
isDirectory: false
53+
)
4354
}
4455

45-
static var appSupportUIZipPath: URL {
56+
static var remoteZipPath: URL {
4657
return Application.supportPath.appendingPathComponent(
47-
"ui-\(Application.version).zip",
58+
"ui-\(Application.version) (Remote).zip",
4859
isDirectory: false
4960
)
5061
}
@@ -247,7 +258,7 @@ class UI: StoreSubscriber {
247258
self.cacheRemote()
248259
} else {
249260
Console.log("Loading Local UI")
250-
UI.unarchiveLocal()
261+
UI.unarchiveZip()
251262
let url = URL(string: "\(UI.localPath)/index.html")!
252263
UI.viewController.load(url)
253264
}
@@ -259,7 +270,7 @@ class UI: StoreSubscriber {
259270
// Only download ui.zip when UI endpoint is remote
260271
if Constants.UI_ENDPOINT_URL.absoluteString.contains(Constants.DOMAIN) {
261272
let destination: DownloadRequest.Destination = { _, _ in
262-
return (UI.appSupportUIZipPath, [.removePreviousFile, .createIntermediateDirectories])
273+
return (UI.remoteZipPath, [.removePreviousFile, .createIntermediateDirectories])
263274
}
264275
AF.download("\(Constants.UI_ENDPOINT_URL)/ui.zip", to: destination).response { resp in
265276
if resp.error == nil {

native/app/eqMac.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@
10381038
CODE_SIGN_IDENTITY = "Developer ID Application";
10391039
CODE_SIGN_STYLE = Manual;
10401040
COMBINE_HIDPI_IMAGES = YES;
1041-
CURRENT_PROJECT_VERSION = 0.2.2;
1041+
CURRENT_PROJECT_VERSION = 0.2.3;
10421042
DEFINES_MODULE = YES;
10431043
DEVELOPMENT_TEAM = JZA6C97KJA;
10441044
ENABLE_HARDENED_RUNTIME = YES;
@@ -1074,7 +1074,7 @@
10741074
"$(PROJECT_DIR)/Source/Vendor",
10751075
);
10761076
MACOSX_DEPLOYMENT_TARGET = 10.12;
1077-
MARKETING_VERSION = v0.2.2;
1077+
MARKETING_VERSION = v0.2.3;
10781078
PRODUCT_BUNDLE_IDENTIFIER = com.bitgapp.eqmac;
10791079
PRODUCT_NAME = "$(TARGET_NAME)";
10801080
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -1098,7 +1098,7 @@
10981098
CODE_SIGN_IDENTITY = "Developer ID Application";
10991099
CODE_SIGN_STYLE = Manual;
11001100
COMBINE_HIDPI_IMAGES = YES;
1101-
CURRENT_PROJECT_VERSION = 0.2.2;
1101+
CURRENT_PROJECT_VERSION = 0.2.3;
11021102
DEFINES_MODULE = YES;
11031103
DEVELOPMENT_TEAM = JZA6C97KJA;
11041104
ENABLE_HARDENED_RUNTIME = YES;
@@ -1134,7 +1134,7 @@
11341134
"$(PROJECT_DIR)/Source/Vendor",
11351135
);
11361136
MACOSX_DEPLOYMENT_TARGET = 10.12;
1137-
MARKETING_VERSION = v0.2.2;
1137+
MARKETING_VERSION = v0.2.3;
11381138
PRODUCT_BUNDLE_IDENTIFIER = com.bitgapp.eqmac;
11391139
PRODUCT_NAME = "$(TARGET_NAME)";
11401140
PROVISIONING_PROFILE_SPECIFIER = "";

ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eqmac",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"scripts": {
55
"start": "ng serve",
66
"build": "rm -rf dist/ && ng build --prod && cd dist/ && zip -r -D ui.zip * -x '*.DS_Store' && cp ui.zip ../../native/app/Embedded",

ui/src/app/sections/help/help.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Option, Options } from 'src/app/components/options/options.component'
33
import { ApplicationService, MacInfo } from 'src/app/services/app.service'
44
import { ConstantsService } from 'src/app/services/constants.service'
55
import { version } from '../../../../package.json'
6+
import { UIService } from '../../services/ui.service.js'
67

78
@Component({
89
selector: 'eqm-help',
@@ -26,9 +27,13 @@ export class HelpComponent implements OnInit {
2627
]
2728
]
2829

29-
constructor (public app: ApplicationService, public CONST: ConstantsService) {}
30+
constructor (
31+
public app: ApplicationService,
32+
public CONST: ConstantsService,
33+
private ui: UIService
34+
) {}
3035

31-
uiVersion = version
36+
uiVersion = `${version} (${this.ui.isLocal ? 'Local' : 'Remote'})`
3237
info: MacInfo
3338
ngOnInit () {
3439
this.fetchInfo()

ui/src/app/services/ui.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ export class UIService extends DataService {
2323
dimensionsChanged = new Subject<UIDimensions>()
2424
settingsChanged = new Subject<UISettings>()
2525

26+
get isLocal () {
27+
return window.location.href.includes('file://')
28+
}
29+
30+
get isRemote () {
31+
return !this.isLocal
32+
}
33+
2634
async getWidth () {
2735
const { width } = await this.request({ method: 'GET', endpoint: '/width' })
2836
return width

0 commit comments

Comments
 (0)