mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 15:47:02 +02:00
Add HIFI_THUNDER_URL environment variable
This commit is contained in:
parent
860b5d0970
commit
ce25ee5377
8 changed files with 274 additions and 1 deletions
|
@ -45,6 +45,8 @@ set(src_files
|
||||||
src/CustomUI.m
|
src/CustomUI.m
|
||||||
src/NSTask+NSTaskExecveAdditions.h
|
src/NSTask+NSTaskExecveAdditions.h
|
||||||
src/NSTask+NSTaskExecveAdditions.m
|
src/NSTask+NSTaskExecveAdditions.m
|
||||||
|
src/HQDefaults.h
|
||||||
|
src/HQDefaults.m
|
||||||
src/main.mm
|
src/main.mm
|
||||||
nib/Window.xib
|
nib/Window.xib
|
||||||
nib/SplashScreen.xib
|
nib/SplashScreen.xib
|
||||||
|
@ -118,6 +120,10 @@ add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
${CMAKE_SOURCE_DIR}/images "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${APP_NAME}.app/Contents/Resources/")
|
${CMAKE_SOURCE_DIR}/images "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${APP_NAME}.app/Contents/Resources/")
|
||||||
|
|
||||||
|
add_custom_command(TARGET ${PROJECT_NAME} PRE_BUILD
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
${CMAKE_SOURCE_DIR}/data/HQDefaults.plist "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${APP_NAME}.app/Contents/Resources/")
|
||||||
|
|
||||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||||
COMMAND updater
|
COMMAND updater
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/updater" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${APP_NAME}.app/Contents/Resources/")
|
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/updater" "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${APP_NAME}.app/Contents/Resources/")
|
||||||
|
@ -146,3 +152,17 @@ set(DMG_SUBFOLDER_ICON "${CMAKE_SOURCE_DIR}/cmake/installer/install-folder.rsrc"
|
||||||
|
|
||||||
set(CPACK_GENERATOR "DragNDrop")
|
set(CPACK_GENERATOR "DragNDrop")
|
||||||
include(CPack)
|
include(CPack)
|
||||||
|
|
||||||
|
include(FindXCTest)
|
||||||
|
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/src)
|
||||||
|
|
||||||
|
xctest_add_bundle(HQLauncherTests HQLauncher
|
||||||
|
${CMAKE_SOURCE_DIR}/src/HQDefaults.m
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/HQDefaultsTests.m
|
||||||
|
${CMAKE_SOURCE_DIR}/tests/Info.plist
|
||||||
|
)
|
||||||
|
|
||||||
|
set_target_properties(HQLauncherTests PROPERTIES
|
||||||
|
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/tests/Info.plist
|
||||||
|
)
|
||||||
|
|
14
launchers/darwin/data/HQDefaults.plist
Normal file
14
launchers/darwin/data/HQDefaults.plist
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>thunderURL</string>
|
||||||
|
<key>defaultValue</key>
|
||||||
|
<string>https://thunder.highfidelity.com</string>
|
||||||
|
<key>environmentVariable</key>
|
||||||
|
<string>HIFI_THUNDER_URL</string>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
</plist>
|
46
launchers/darwin/src/HQDefaults.h
Normal file
46
launchers/darwin/src/HQDefaults.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
//
|
||||||
|
// Created by Matt Hardcastle <m@hardcastle.com>
|
||||||
|
// Copyright 2018 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
/*
|
||||||
|
* `HQDefaults` loads defaults from the `HQDefaults.plist` and allows
|
||||||
|
* defaults in that plist to be overwritten using an environment variable.
|
||||||
|
*
|
||||||
|
* For example, the following `HQDefaults.plist` will set a default "foo"
|
||||||
|
* with a value "bar". The "bar" value can be overwritten with the value of
|
||||||
|
* the FOO environment variables, if the FOO environment variable is set.
|
||||||
|
*
|
||||||
|
* <?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
* <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
* <plist version="1.0">
|
||||||
|
* <array>
|
||||||
|
* <dict>
|
||||||
|
* <key>name</key>
|
||||||
|
* <string>foo</string>
|
||||||
|
* <key>defaultValue</key>
|
||||||
|
* <string>bar</string>
|
||||||
|
* <key>environmentVariable</key>
|
||||||
|
* <string>FOO</string>
|
||||||
|
* </dict>
|
||||||
|
* </array>
|
||||||
|
* </plist>
|
||||||
|
*/
|
||||||
|
|
||||||
|
@interface HQDefaults : NSObject
|
||||||
|
|
||||||
|
-(NSString *)defaultNamed:(NSString *)name;
|
||||||
|
+(HQDefaults *)sharedDefaults;
|
||||||
|
|
||||||
|
@property (strong, readonly) NSDictionary<NSString *, NSString *> *defaults;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
74
launchers/darwin/src/HQDefaults.m
Normal file
74
launchers/darwin/src/HQDefaults.m
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
//
|
||||||
|
// Created by Matt Hardcastle <m@hardcastle.com>
|
||||||
|
// Copyright 2018 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "HQDefaults.h"
|
||||||
|
|
||||||
|
@implementation HQDefaults;
|
||||||
|
|
||||||
|
// This initializer is for testing purposes. See `init()` for normal use.
|
||||||
|
-(id)initWithArray:(NSArray *)array environment:(NSDictionary<NSString *, NSString *> *)environment
|
||||||
|
{
|
||||||
|
self = [super init];
|
||||||
|
if (self) {
|
||||||
|
NSMutableDictionary<NSString *, NSString *> *__defaults = [[NSMutableDictionary alloc] init];
|
||||||
|
NSString *name, *defaultValue, *environmentVariable;
|
||||||
|
|
||||||
|
for (NSDictionary *obj in array) {
|
||||||
|
NSMutableArray<NSString *> *missingKeys = [[NSMutableArray alloc] init];
|
||||||
|
if ((name = [obj objectForKey:@"name"]) == nil) {
|
||||||
|
[missingKeys addObject:@"name"];
|
||||||
|
}
|
||||||
|
if ((defaultValue = [obj objectForKey:@"defaultValue"]) == nil) {
|
||||||
|
[missingKeys addObject:@"defaultValue"];
|
||||||
|
}
|
||||||
|
if ([missingKeys count] > 0) {
|
||||||
|
@throw [NSException exceptionWithName:@"InvalidHQDefaults"
|
||||||
|
reason:@"A required key is missing"
|
||||||
|
userInfo:@{@"missingKeys": missingKeys}];
|
||||||
|
}
|
||||||
|
|
||||||
|
environmentVariable = [obj objectForKey:@"environmentVariable"];
|
||||||
|
if (environmentVariable == nil) {
|
||||||
|
__defaults[name] = defaultValue;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *value = environment[environmentVariable];
|
||||||
|
__defaults[name] = value == nil ? defaultValue : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the dictionary immutable.
|
||||||
|
_defaults = __defaults;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize an `HQLauncher` object using the bundles "HQDefaults.plist" and the current process's environment.
|
||||||
|
-(id)init {
|
||||||
|
NSBundle *bundle = [NSBundle mainBundle];
|
||||||
|
NSString *defaultsPath = [bundle pathForResource:@"HQDefaults" ofType:@"plist"];
|
||||||
|
NSArray *array = [NSArray arrayWithContentsOfFile:defaultsPath];
|
||||||
|
return [self initWithArray:array environment:NSProcessInfo.processInfo.environment];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve a default.
|
||||||
|
-(NSString *)defaultNamed:(NSString *)name {
|
||||||
|
return _defaults[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
// A singleton HQDefaults using the mainBundle's "HQDefaults.plist" and the environment.
|
||||||
|
+(HQDefaults *)sharedDefaults {
|
||||||
|
static HQDefaults *defaults = nil;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
defaults = [[HQDefaults alloc] init];
|
||||||
|
});
|
||||||
|
return defaults;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
|
@ -1,6 +1,7 @@
|
||||||
#import "LatestBuildRequest.h"
|
#import "LatestBuildRequest.h"
|
||||||
#import "Launcher.h"
|
#import "Launcher.h"
|
||||||
#import "Settings.h"
|
#import "Settings.h"
|
||||||
|
#import "HQDefaults.h"
|
||||||
|
|
||||||
@implementation LatestBuildRequest
|
@implementation LatestBuildRequest
|
||||||
|
|
||||||
|
@ -8,7 +9,13 @@
|
||||||
NSString* buildsURL = [[[NSProcessInfo processInfo] environment] objectForKey:@"HQ_LAUNCHER_BUILDS_URL"];
|
NSString* buildsURL = [[[NSProcessInfo processInfo] environment] objectForKey:@"HQ_LAUNCHER_BUILDS_URL"];
|
||||||
|
|
||||||
if ([buildsURL length] == 0) {
|
if ([buildsURL length] == 0) {
|
||||||
buildsURL = @"https://thunder.highfidelity.com/builds/api/tags/latest?format=json";
|
NSString *thunderURL = [[HQDefaults sharedDefaults] defaultNamed:@"thunderURL"];
|
||||||
|
if (thunderURL == nil) {
|
||||||
|
@throw [NSException exceptionWithName:@"DefaultMissing"
|
||||||
|
reason:@"The thunderURL default is missing"
|
||||||
|
userInfo:nil];
|
||||||
|
}
|
||||||
|
buildsURL = [NSString stringWithFormat:@"%@/builds/api/tags/latest?format=json", thunderURL];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSLog(@"Making request for builds to: %@", buildsURL);
|
NSLog(@"Making request for builds to: %@", buildsURL);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#import "Settings.h"
|
#import "Settings.h"
|
||||||
#import "NSTask+NSTaskExecveAdditions.h"
|
#import "NSTask+NSTaskExecveAdditions.h"
|
||||||
#import "Interface.h"
|
#import "Interface.h"
|
||||||
|
#import "HQDefaults.h"
|
||||||
|
|
||||||
@interface Launcher ()
|
@interface Launcher ()
|
||||||
|
|
||||||
|
@ -483,6 +484,17 @@ static BOOL const DELETE_ZIP_FILES = TRUE;
|
||||||
[self.window makeKeyAndOrderFront:self];
|
[self.window makeKeyAndOrderFront:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void)applicationDidFinishLaunching:(NSNotification *)notification
|
||||||
|
{
|
||||||
|
// Sanity check the HQDefaults so we fail early if there's an issue.
|
||||||
|
HQDefaults *defaults = [HQDefaults sharedDefaults];
|
||||||
|
if ([defaults defaultNamed:@"thunderURL"] == nil) {
|
||||||
|
@throw [NSException exceptionWithName:@"DefaultsNotConfigured"
|
||||||
|
reason:@"thunderURL is not configured"
|
||||||
|
userInfo:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void) setDownloadFilename:(NSString *)aFilename
|
- (void) setDownloadFilename:(NSString *)aFilename
|
||||||
{
|
{
|
||||||
self.filename = aFilename;
|
self.filename = aFilename;
|
||||||
|
|
78
launchers/darwin/tests/HQDefaultsTests.m
Normal file
78
launchers/darwin/tests/HQDefaultsTests.m
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
//
|
||||||
|
// Created by Matt Hardcastle <m@hardcastle.com>
|
||||||
|
// Copyright 2018 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <XCTest/XCTest.h>
|
||||||
|
|
||||||
|
#import "HQDefaults.h"
|
||||||
|
|
||||||
|
// Expose the `initWithArray:environment` initializer for testing.
|
||||||
|
@interface HQDefaults(HQDefaultsTesting)
|
||||||
|
-(id)initWithArray:(NSArray *)array environment:(NSDictionary<NSString *, NSString *> *)environment;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface HQDefaultsTests : XCTestCase
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation HQDefaultsTests
|
||||||
|
|
||||||
|
// If there is not environment the default value should be used.
|
||||||
|
- (void)testNoEnvironmentReturnsDefaultValue {
|
||||||
|
NSArray *array = @[@{@"name":@"foo",
|
||||||
|
@"environmentVariable":@"FOO",
|
||||||
|
@"defaultValue":@"bar"}];
|
||||||
|
|
||||||
|
HQDefaults *defaults = [[HQDefaults alloc] initWithArray:array
|
||||||
|
environment:@{}];
|
||||||
|
|
||||||
|
XCTAssertEqual([defaults defaultNamed:@"foo"], @"bar");
|
||||||
|
}
|
||||||
|
|
||||||
|
// The value from the environment should overwrite the default value.
|
||||||
|
- (void)testEnvironmentOverWritesDefaultValue {
|
||||||
|
NSArray *array = @[@{@"name":@"foo",
|
||||||
|
@"environmentVariable":@"FOO",
|
||||||
|
@"defaultValue":@"bar"}];
|
||||||
|
NSDictionary *environment = @{@"FOO":@"FOO_VALUE_FROM_ENVIRONMENT"};
|
||||||
|
|
||||||
|
HQDefaults *defaults = [[HQDefaults alloc] initWithArray:array environment:environment];
|
||||||
|
|
||||||
|
NSString *value = [defaults defaultNamed:@"foo"];
|
||||||
|
|
||||||
|
XCTAssertEqual(value, @"FOO_VALUE_FROM_ENVIRONMENT");
|
||||||
|
}
|
||||||
|
|
||||||
|
// An exception should be thrown if a defaults object is missing `name`.
|
||||||
|
- (void)testMissingNameThrowsException {
|
||||||
|
NSArray *array = @[@{@"defaultValue":@"bar"}];
|
||||||
|
XCTAssertThrowsSpecificNamed([[HQDefaults alloc] initWithArray:array environment:@{}],
|
||||||
|
NSException,
|
||||||
|
@"InvalidHQDefaults");
|
||||||
|
}
|
||||||
|
|
||||||
|
// An exception should be thrown if a defaults object is missing `defaultValue`.
|
||||||
|
- (void)testMissingDefaultValueThrowsException {
|
||||||
|
NSArray *array = @[@{@"name":@"foo" }];
|
||||||
|
XCTAssertThrowsSpecificNamed([[HQDefaults alloc] initWithArray:array environment:@{}],
|
||||||
|
NSException,
|
||||||
|
@"InvalidHQDefaults");
|
||||||
|
}
|
||||||
|
|
||||||
|
// An exception should **NOT** be thrown if a defaults object is missing `environmentVariable`.
|
||||||
|
- (void)testMissingEnvironmentVariableDoesNotThrowException {
|
||||||
|
NSArray *array = @[@{@"name":@"foo", @"defaultValue":@"bar"}];
|
||||||
|
XCTAssertNoThrow([[HQDefaults alloc] initWithArray:array environment:@{}]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// A `nil` should be returned if a default is missing.
|
||||||
|
- (void)testEmptyDefaultIsNil {
|
||||||
|
HQDefaults *defaults = [[HQDefaults alloc] initWithArray:@[] environment:@{}];
|
||||||
|
XCTAssertNil([defaults defaultNamed:@"foo"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
22
launchers/darwin/tests/Info.plist
Normal file
22
launchers/darwin/tests/Info.plist
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
|
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
<string>6.0</string>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>$(PRODUCT_NAME)</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>BNDL</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>1.0</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>1</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
Loading…
Reference in a new issue