mac close interface and launcher and fix compile warnings

This commit is contained in:
dante ruiz 2019-09-30 14:24:14 -07:00
parent d5f042c361
commit 13e8dc036c
7 changed files with 56 additions and 9 deletions

View file

@ -35,6 +35,7 @@ include(ExternalProject)
if (APPLE) if (APPLE)
set(CMAKE_EXE_LINKER_FLAGS "-framework Cocoa -framework CoreServices -framework Carbon -framework IOKit -framework Security -framework SystemConfiguration") set(CMAKE_EXE_LINKER_FLAGS "-framework Cocoa -framework CoreServices -framework Carbon -framework IOKit -framework Security -framework SystemConfiguration")
add_compile_options(-W -Wall -Wextra -Wpedantic)
endif() endif()
if (WIN32) if (WIN32)

View file

@ -14,6 +14,9 @@ void swapLaunchers(const QString& oldLauncherPath = QString(), const QString& ne
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
bool replaceDirectory(const QString& orginalDirectory, const QString& newDirectory); bool replaceDirectory(const QString& orginalDirectory, const QString& newDirectory);
void closeInterfaceIfRunning();
void waitForInterfaceToClose();
bool isLauncherAlreadyRunning();
#endif #endif
#ifdef Q_OS_WIN #ifdef Q_OS_WIN

View file

@ -70,3 +70,43 @@ bool replaceDirectory(const QString& orginalDirectory, const QString& newDirecto
return (bool) [fileManager replaceItemAtURL:[UpdaterHelper NSStringToNSURL:orginalDirectory.toNSString()] withItemAtURL:[UpdaterHelper NSStringToNSURL:newDirectory.toNSString()] return (bool) [fileManager replaceItemAtURL:[UpdaterHelper NSStringToNSURL:orginalDirectory.toNSString()] withItemAtURL:[UpdaterHelper NSStringToNSURL:newDirectory.toNSString()]
backupItemName:nil options:NSFileManagerItemReplacementUsingNewMetadataOnly resultingItemURL:&destinationUrl error:nil]; backupItemName:nil options:NSFileManagerItemReplacementUsingNewMetadataOnly resultingItemURL:&destinationUrl error:nil];
} }
void waitForInterfaceToClose() {
bool interfaceRunning = true;
while (interfaceRunning) {
interfaceRunning = false;
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
NSArray* apps = [workspace runningApplications];
for (NSRunningApplication* app in apps) {
if ([[app bundleIdentifier] isEqualToString:@"com.highfidelity.interface"] ||
[[app bundleIdentifier] isEqualToString:@"com.highfidelity.interface-pr"]) {
interfaceRunning = true;
break;
}
}
}
}
bool isLauncherAlreadyRunning() {
NSArray* apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.highfidelity.launcher"];
NSLog(@"Count: %lu", [apps count]);
if ([apps count] > 1) {
NSLog(@"launcher is already running");
return true;
}
return false;
}
void closeInterfaceIfRunning() {
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
NSArray* apps = [workspace runningApplications];
for (NSRunningApplication* app in apps) {
if ([[app bundleIdentifier] isEqualToString:@"com.highfidelity.interface"] ||
[[app bundleIdentifier] isEqualToString:@"com.highfidelity.interface-pr"]) {
[app terminate];
}
}
}

View file

@ -31,9 +31,9 @@ struct LoginResponse {
class LauncherState : public QObject { class LauncherState : public QObject {
Q_OBJECT Q_OBJECT
Q_PROPERTY(UIState uiState READ getUIState NOTIFY uiStateChanged); Q_PROPERTY(UIState uiState READ getUIState NOTIFY uiStateChanged)
Q_PROPERTY(ApplicationState applicationState READ getApplicationState NOTIFY applicationStateChanged); Q_PROPERTY(ApplicationState applicationState READ getApplicationState NOTIFY applicationStateChanged)
Q_PROPERTY(float downloadProgress READ getDownloadProgress NOTIFY downloadProgressChanged); Q_PROPERTY(float downloadProgress READ getDownloadProgress NOTIFY downloadProgressChanged)
public: public:
LauncherState(); LauncherState();

View file

@ -15,7 +15,7 @@ toCArray(NSArray<NSString *> *array)
@throw exception; @throw exception;
} }
char *str; char *str;
for (int i = 0; i < [array count]; i++) { for (NSUInteger i = 0; i < [array count]; i++) {
str = (char *) [array[i] UTF8String]; str = (char *) [array[i] UTF8String];
if (str == NULL) { if (str == NULL) {
NSException *exception = [NSException NSException *exception = [NSException
@ -25,7 +25,7 @@ toCArray(NSArray<NSString *> *array)
@throw exception; @throw exception;
} }
if (asprintf(&cArray[i], "%s", str) == -1) { if (asprintf(&cArray[i], "%s", str) == -1) {
for (int j = 0; j < i; j++) { for (NSUInteger j = 0; j < i; j++) {
free(cArray[j]); free(cArray[j]);
} }
free(cArray); free(cArray);
@ -54,13 +54,11 @@ toCArray(NSArray<NSString *> *array)
char** envp = toCArray(env); char** envp = toCArray(env);
// `execve` replaces the current process with `path`. // `execve` replaces the current process with `path`.
// It will only return if it fails to replace the current process. // It will only return if it fails to replace the current process.
NSLog(@"------------>");
chdir(dirname(args[0])); chdir(dirname(args[0]));
execve(args[0], (char * const *)args, envp); execve(args[0], (char * const *)args, envp);
NSLog(@"----------- FAILED ");
// If we're here `execve` failed. :( // If we're here `execve` failed. :(
for (int i = 0; i < [[self arguments] count]; i++) { for (NSUInteger i = 0; i < [[self arguments] count]; i++) {
free((void *) args[i]); free((void *) args[i]);
} }
free((void *) args); free((void *) args);

View file

@ -49,7 +49,7 @@ void Unzipper::run() {
uint64_t totalSize = 0; uint64_t totalSize = 0;
uint64_t totalCompressedSize = 0; uint64_t totalCompressedSize = 0;
bool _shouldFail = false; //bool _shouldFail = false;
for (int i = 0; i < fileCount; i++) { for (int i = 0; i < fileCount; i++) {
if (!mz_zip_reader_file_stat(&zip_archive, i, &file_stat)) continue; if (!mz_zip_reader_file_stat(&zip_archive, i, &file_stat)) continue;

View file

@ -31,6 +31,11 @@ bool hasSuffix(const std::string path, const std::string suffix) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Q_INIT_RESOURCE(resources); Q_INIT_RESOURCE(resources);
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
if (isLauncherAlreadyRunning()) {
return 0;
}
closeInterfaceIfRunning();
// waitForInterfaceToClose();
// auto updater // auto updater
if (argc == 3) { if (argc == 3) {
if (hasSuffix(argv[1], "app") && hasSuffix(argv[2], "app")) { if (hasSuffix(argv[1], "app") && hasSuffix(argv[2], "app")) {