mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-07 04:53:28 +02:00
mac close interface and launcher and fix compile warnings
This commit is contained in:
parent
d5f042c361
commit
13e8dc036c
7 changed files with 56 additions and 9 deletions
|
@ -35,6 +35,7 @@ include(ExternalProject)
|
|||
|
||||
if (APPLE)
|
||||
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()
|
||||
if (WIN32)
|
||||
|
||||
|
|
|
@ -14,6 +14,9 @@ void swapLaunchers(const QString& oldLauncherPath = QString(), const QString& ne
|
|||
|
||||
#ifdef Q_OS_MAC
|
||||
bool replaceDirectory(const QString& orginalDirectory, const QString& newDirectory);
|
||||
void closeInterfaceIfRunning();
|
||||
void waitForInterfaceToClose();
|
||||
bool isLauncherAlreadyRunning();
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
|
|
|
@ -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()]
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ struct LoginResponse {
|
|||
class LauncherState : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(UIState uiState READ getUIState NOTIFY uiStateChanged);
|
||||
Q_PROPERTY(ApplicationState applicationState READ getApplicationState NOTIFY applicationStateChanged);
|
||||
Q_PROPERTY(float downloadProgress READ getDownloadProgress NOTIFY downloadProgressChanged);
|
||||
Q_PROPERTY(UIState uiState READ getUIState NOTIFY uiStateChanged)
|
||||
Q_PROPERTY(ApplicationState applicationState READ getApplicationState NOTIFY applicationStateChanged)
|
||||
Q_PROPERTY(float downloadProgress READ getDownloadProgress NOTIFY downloadProgressChanged)
|
||||
|
||||
public:
|
||||
LauncherState();
|
||||
|
|
|
@ -15,7 +15,7 @@ toCArray(NSArray<NSString *> *array)
|
|||
@throw exception;
|
||||
}
|
||||
char *str;
|
||||
for (int i = 0; i < [array count]; i++) {
|
||||
for (NSUInteger i = 0; i < [array count]; i++) {
|
||||
str = (char *) [array[i] UTF8String];
|
||||
if (str == NULL) {
|
||||
NSException *exception = [NSException
|
||||
|
@ -25,7 +25,7 @@ toCArray(NSArray<NSString *> *array)
|
|||
@throw exception;
|
||||
}
|
||||
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);
|
||||
|
@ -54,13 +54,11 @@ toCArray(NSArray<NSString *> *array)
|
|||
char** envp = toCArray(env);
|
||||
// `execve` replaces the current process with `path`.
|
||||
// It will only return if it fails to replace the current process.
|
||||
NSLog(@"------------>");
|
||||
chdir(dirname(args[0]));
|
||||
execve(args[0], (char * const *)args, envp);
|
||||
|
||||
NSLog(@"----------- 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);
|
||||
|
|
|
@ -49,7 +49,7 @@ void Unzipper::run() {
|
|||
|
||||
uint64_t totalSize = 0;
|
||||
uint64_t totalCompressedSize = 0;
|
||||
bool _shouldFail = false;
|
||||
//bool _shouldFail = false;
|
||||
for (int i = 0; i < fileCount; i++) {
|
||||
if (!mz_zip_reader_file_stat(&zip_archive, i, &file_stat)) continue;
|
||||
|
||||
|
|
|
@ -31,6 +31,11 @@ bool hasSuffix(const std::string path, const std::string suffix) {
|
|||
int main(int argc, char *argv[]) {
|
||||
Q_INIT_RESOURCE(resources);
|
||||
#ifdef Q_OS_MAC
|
||||
if (isLauncherAlreadyRunning()) {
|
||||
return 0;
|
||||
}
|
||||
closeInterfaceIfRunning();
|
||||
// waitForInterfaceToClose();
|
||||
// auto updater
|
||||
if (argc == 3) {
|
||||
if (hasSuffix(argv[1], "app") && hasSuffix(argv[2], "app")) {
|
||||
|
|
Loading…
Reference in a new issue