2017-12-11 14:45:29 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-12-11 14:45:29 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-12-11 14:45:29 +00:00
|
|
|
*/
|
|
|
|
#include "platform/mac/launcher_mac.h"
|
|
|
|
|
2017-12-12 07:52:53 +00:00
|
|
|
#include "core/crash_reports.h"
|
2018-07-11 22:14:44 +00:00
|
|
|
#include "core/update_checker.h"
|
2020-10-29 19:56:13 +00:00
|
|
|
#include "base/platform/base_platform_file_utilities.h"
|
2019-09-26 10:20:34 +00:00
|
|
|
#include "base/platform/mac/base_utilities_mac.h"
|
2017-12-12 07:52:53 +00:00
|
|
|
|
|
|
|
#include <Cocoa/Cocoa.h>
|
|
|
|
#include <CoreFoundation/CFURL.h>
|
2018-06-03 19:52:23 +00:00
|
|
|
#include <sys/sysctl.h>
|
2017-12-12 07:52:53 +00:00
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
namespace Platform {
|
2018-06-03 19:52:23 +00:00
|
|
|
|
|
|
|
Launcher::Launcher(int argc, char *argv[])
|
2020-12-29 07:17:43 +00:00
|
|
|
: Core::Launcher(argc, argv) {
|
2018-06-03 19:52:23 +00:00
|
|
|
}
|
2017-12-11 14:45:29 +00:00
|
|
|
|
|
|
|
void Launcher::initHook() {
|
|
|
|
// macOS Retina display support is working fine, others are not.
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling, false);
|
|
|
|
}
|
|
|
|
|
2017-12-12 07:52:53 +00:00
|
|
|
bool Launcher::launchUpdater(UpdaterLaunch action) {
|
|
|
|
if (cExeName().isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
@autoreleasepool {
|
|
|
|
|
|
|
|
#ifdef OS_MAC_STORE
|
|
|
|
// In AppStore version we don't have Updater.
|
|
|
|
// We just relaunch our app.
|
|
|
|
if (action == UpdaterLaunch::JustRelaunch) {
|
|
|
|
NSDictionary *conf = [NSDictionary dictionaryWithObject:[NSArray array] forKey:NSWorkspaceLaunchConfigurationArguments];
|
|
|
|
[[NSWorkspace sharedWorkspace] launchApplicationAtURL:[NSURL fileURLWithPath:Q2NSString(cExeDir() + cExeName())] options:NSWorkspaceLaunchAsync | NSWorkspaceLaunchNewInstance configuration:conf error:0];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // OS_MAC_STORE
|
|
|
|
|
|
|
|
NSString *path = @"", *args = @"";
|
|
|
|
@try {
|
|
|
|
path = [[NSBundle mainBundle] bundlePath];
|
|
|
|
if (!path) {
|
|
|
|
LOG(("Could not get bundle path!!"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
path = [path stringByAppendingString:@"/Contents/Frameworks/Updater"];
|
2020-10-29 19:56:13 +00:00
|
|
|
base::Platform::RemoveQuarantine(QFile::decodeName([path fileSystemRepresentation]));
|
2017-12-12 07:52:53 +00:00
|
|
|
|
|
|
|
NSMutableArray *args = [[NSMutableArray alloc] initWithObjects:@"-workpath", Q2NSString(cWorkingDir()), @"-procid", nil];
|
|
|
|
[args addObject:[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]]];
|
|
|
|
if (cRestartingToSettings()) [args addObject:@"-tosettings"];
|
|
|
|
if (action == UpdaterLaunch::JustRelaunch) [args addObject:@"-noupdate"];
|
|
|
|
if (cLaunchMode() == LaunchModeAutoStart) [args addObject:@"-autostart"];
|
2018-06-05 13:32:26 +00:00
|
|
|
if (Logs::DebugEnabled()) [args addObject:@"-debug"];
|
2017-12-12 07:52:53 +00:00
|
|
|
if (cStartInTray()) [args addObject:@"-startintray"];
|
2020-05-20 00:10:21 +00:00
|
|
|
if (cUseFreeType()) [args addObject:@"-freetype"];
|
2017-12-12 07:52:53 +00:00
|
|
|
if (cDataFile() != qsl("data")) {
|
|
|
|
[args addObject:@"-key"];
|
|
|
|
[args addObject:Q2NSString(cDataFile())];
|
|
|
|
}
|
|
|
|
if (customWorkingDir()) {
|
|
|
|
[args addObject:@"-workdir_custom"];
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_LOG(("Application Info: executing %1 %2").arg(NS2QString(path)).arg(NS2QString([args componentsJoinedByString:@" "])));
|
|
|
|
Logs::closeMain();
|
|
|
|
CrashReports::Finish();
|
|
|
|
if (![NSTask launchedTaskWithLaunchPath:path arguments:args]) {
|
|
|
|
DEBUG_LOG(("Task not launched while executing %1 %2").arg(NS2QString(path)).arg(NS2QString([args componentsJoinedByString:@" "])));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@catch (NSException *exception) {
|
|
|
|
LOG(("Exception caught while executing %1 %2").arg(NS2QString(path)).arg(NS2QString(args)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
@finally {
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-11 14:45:29 +00:00
|
|
|
} // namespace Platform
|