2014-11-25 20:15:18 +00:00
|
|
|
/*
|
2014-06-14 19:32:11 +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.
|
2016-01-11 15:43: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
|
2014-06-14 19:32:11 +00:00
|
|
|
*/
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "platform/mac/specific_mac_p.h"
|
2014-06-14 19:32:11 +00:00
|
|
|
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2015-07-13 17:55:59 +00:00
|
|
|
#include "mainwidget.h"
|
2019-04-07 06:59:37 +00:00
|
|
|
#include "core/sandbox.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/application.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "core/core_settings.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "core/crash_reports.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2019-02-13 12:36:59 +00:00
|
|
|
#include "media/audio/media_audio.h"
|
2016-09-23 16:04:26 +00:00
|
|
|
#include "media/player/media_player_instance.h"
|
2019-09-26 10:20:34 +00:00
|
|
|
#include "base/platform/mac/base_utilities_mac.h"
|
2019-09-17 16:13:12 +00:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2017-04-12 11:58:37 +00:00
|
|
|
#include "base/timer.h"
|
2019-01-21 13:42:21 +00:00
|
|
|
#include "styles/style_window.h"
|
2021-01-23 12:14:37 +00:00
|
|
|
#include "platform/platform_specific.h"
|
2014-06-18 18:37:44 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtGui/QWindow>
|
|
|
|
#include <QtWidgets/QApplication>
|
2019-11-05 11:27:21 +00:00
|
|
|
#if __has_include(<QtCore/QOperatingSystemVersion>)
|
2019-10-11 06:32:26 +00:00
|
|
|
#include <QtCore/QOperatingSystemVersion>
|
2019-11-05 11:27:21 +00:00
|
|
|
#endif // __has_include(<QtCore/QOperatingSystemVersion>)
|
2014-06-14 19:32:11 +00:00
|
|
|
#include <Cocoa/Cocoa.h>
|
2014-06-17 06:06:01 +00:00
|
|
|
#include <CoreFoundation/CFURL.h>
|
2016-11-08 14:07:25 +00:00
|
|
|
#include <IOKit/IOKitLib.h>
|
2015-07-13 17:55:59 +00:00
|
|
|
#include <IOKit/hidsystem/ev_keymap.h>
|
2016-10-17 14:57:14 +00:00
|
|
|
#include <SPMediaKeyTap.h>
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
namespace {
|
|
|
|
|
2017-05-02 07:25:20 +00:00
|
|
|
constexpr auto kIgnoreActivationTimeoutMs = 500;
|
2017-04-12 11:58:37 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
using Platform::Q2NSString;
|
|
|
|
using Platform::NS2QString;
|
|
|
|
|
2015-01-02 15:07:48 +00:00
|
|
|
@interface qVisualize : NSObject {
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (id)str:(const QString &)str;
|
|
|
|
- (id)initWithString:(const QString &)str;
|
|
|
|
|
|
|
|
+ (id)bytearr:(const QByteArray &)arr;
|
|
|
|
- (id)initWithByteArray:(const QByteArray &)arr;
|
|
|
|
|
|
|
|
- (id)debugQuickLookObject;
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
@end // @interface qVisualize
|
2015-01-02 15:07:48 +00:00
|
|
|
|
|
|
|
@implementation qVisualize {
|
|
|
|
NSString *value;
|
2017-04-12 11:58:37 +00:00
|
|
|
|
2015-01-02 15:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (id)bytearr:(const QByteArray &)arr {
|
|
|
|
return [[qVisualize alloc] initWithByteArray:arr];
|
|
|
|
}
|
|
|
|
- (id)initWithByteArray:(const QByteArray &)arr {
|
|
|
|
if (self = [super init]) {
|
|
|
|
value = [NSString stringWithUTF8String:arr.constData()];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (id)str:(const QString &)str {
|
|
|
|
return [[qVisualize alloc] initWithString:str];
|
|
|
|
}
|
|
|
|
- (id)initWithString:(const QString &)str {
|
|
|
|
if (self = [super init]) {
|
|
|
|
value = [NSString stringWithUTF8String:str.toUtf8().constData()];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)debugQuickLookObject {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
@end // @implementation qVisualize
|
2015-01-02 15:07:48 +00:00
|
|
|
|
2014-09-20 21:31:03 +00:00
|
|
|
@interface ApplicationDelegate : NSObject<NSApplicationDelegate> {
|
2017-04-12 11:58:37 +00:00
|
|
|
}
|
2016-10-17 14:57:14 +00:00
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
- (BOOL) applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag;
|
|
|
|
- (void) applicationDidFinishLaunching:(NSNotification *)aNotification;
|
|
|
|
- (void) applicationDidBecomeActive:(NSNotification *)aNotification;
|
2018-08-04 12:06:39 +00:00
|
|
|
- (void) applicationDidResignActive:(NSNotification *)aNotification;
|
2017-04-12 11:58:37 +00:00
|
|
|
- (void) receiveWakeNote:(NSNotification*)note;
|
2016-10-17 14:57:14 +00:00
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
- (void) setWatchingMediaKeys:(bool)watching;
|
|
|
|
- (bool) isWatchingMediaKeys;
|
|
|
|
- (void) mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)event;
|
2014-09-20 21:31:03 +00:00
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
- (void) ignoreApplicationActivationRightNow;
|
2014-09-20 21:31:03 +00:00
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
@end // @interface ApplicationDelegate
|
2014-09-20 21:31:03 +00:00
|
|
|
|
2014-12-03 15:07:24 +00:00
|
|
|
ApplicationDelegate *_sharedDelegate = nil;
|
|
|
|
|
2014-09-20 21:31:03 +00:00
|
|
|
@implementation ApplicationDelegate {
|
2017-04-12 11:58:37 +00:00
|
|
|
SPMediaKeyTap *_keyTap;
|
|
|
|
bool _watchingMediaKeys;
|
|
|
|
bool _ignoreActivation;
|
|
|
|
base::Timer _ignoreActivationStop;
|
2014-09-20 21:31:03 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
- (BOOL) applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag {
|
2014-09-20 21:31:03 +00:00
|
|
|
if (App::wnd() && App::wnd()->isHidden()) App::wnd()->showFromTray();
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
- (void) applicationDidFinishLaunching:(NSNotification *)aNotification {
|
|
|
|
_keyTap = nullptr;
|
|
|
|
_watchingMediaKeys = false;
|
|
|
|
_ignoreActivation = false;
|
|
|
|
_ignoreActivationStop.setCallback([self] {
|
|
|
|
_ignoreActivation = false;
|
|
|
|
});
|
2016-10-19 22:02:21 +00:00
|
|
|
#ifndef OS_MAC_STORE
|
2016-10-17 14:57:14 +00:00
|
|
|
if ([SPMediaKeyTap usesGlobalMediaKeyTap]) {
|
2019-06-03 14:41:23 +00:00
|
|
|
if (!Platform::IsMac10_14OrGreater()) {
|
2018-09-26 10:18:29 +00:00
|
|
|
_keyTap = [[SPMediaKeyTap alloc] initWithDelegate:self];
|
|
|
|
} else {
|
|
|
|
// In macOS Mojave it requires accessibility features.
|
2019-06-03 14:41:23 +00:00
|
|
|
LOG(("Media key monitoring disabled starting with Mojave."));
|
2018-09-26 10:18:29 +00:00
|
|
|
}
|
2016-10-17 14:57:14 +00:00
|
|
|
} else {
|
|
|
|
LOG(("Media key monitoring disabled"));
|
|
|
|
}
|
2016-10-19 22:02:21 +00:00
|
|
|
#endif // else for !OS_MAC_STORE
|
2016-10-17 14:57:14 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
- (void) applicationDidBecomeActive:(NSNotification *)aNotification {
|
2020-10-29 16:26:58 +00:00
|
|
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
|
|
|
if (Core::IsAppLaunched() && !_ignoreActivation) {
|
|
|
|
Core::App().handleAppActivated();
|
|
|
|
if (auto window = App::wnd()) {
|
|
|
|
if (window->isHidden()) {
|
|
|
|
window->showFromTray();
|
|
|
|
}
|
2017-02-20 10:36:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-29 16:26:58 +00:00
|
|
|
});
|
2014-11-12 20:30:26 +00:00
|
|
|
}
|
|
|
|
|
2018-08-04 12:06:39 +00:00
|
|
|
- (void) applicationDidResignActive:(NSNotification *)aNotification {
|
|
|
|
}
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
- (void) receiveWakeNote:(NSNotification*)aNotification {
|
2020-11-05 12:05:29 +00:00
|
|
|
if (!Core::IsAppLaunched()) {
|
|
|
|
return;
|
2017-02-18 13:32:38 +00:00
|
|
|
}
|
2020-11-19 13:23:51 +00:00
|
|
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
|
|
|
Core::App().checkLocalTime();
|
|
|
|
|
|
|
|
LOG(("Audio Info: "
|
|
|
|
"-receiveWakeNote: received, scheduling detach from audio device"));
|
|
|
|
Media::Audio::ScheduleDetachFromDeviceSafe();
|
2017-01-24 21:24:39 +00:00
|
|
|
|
2020-11-19 13:23:51 +00:00
|
|
|
Core::App().settings().setSystemDarkMode(Platform::IsDarkMode());
|
|
|
|
});
|
2014-11-12 20:30:26 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
- (void) setWatchingMediaKeys:(bool)watching {
|
|
|
|
if (_watchingMediaKeys != watching) {
|
|
|
|
_watchingMediaKeys = watching;
|
|
|
|
if (_keyTap) {
|
2016-10-22 14:35:37 +00:00
|
|
|
#ifndef OS_MAC_STORE
|
2017-04-12 11:58:37 +00:00
|
|
|
if (_watchingMediaKeys) {
|
|
|
|
[_keyTap startWatchingMediaKeys];
|
2016-10-22 14:35:37 +00:00
|
|
|
} else {
|
2017-04-12 11:58:37 +00:00
|
|
|
[_keyTap stopWatchingMediaKeys];
|
2016-10-22 14:35:37 +00:00
|
|
|
}
|
|
|
|
#endif // else for !OS_MAC_STORE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
- (bool) isWatchingMediaKeys {
|
|
|
|
return _watchingMediaKeys;
|
2016-10-22 14:35:37 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
- (void) mediaKeyTap:(SPMediaKeyTap*)keyTap receivedMediaKeyEvent:(NSEvent*)e {
|
2019-04-07 06:59:37 +00:00
|
|
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
|
|
|
if (e && [e type] == NSSystemDefined && [e subtype] == SPSystemDefinedEventMediaKeys) {
|
|
|
|
objc_handleMediaKeyEvent(e);
|
|
|
|
}
|
|
|
|
});
|
2016-10-17 14:57:14 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
- (void) ignoreApplicationActivationRightNow {
|
|
|
|
_ignoreActivation = true;
|
|
|
|
_ignoreActivationStop.callOnce(kIgnoreActivationTimeoutMs);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end // @implementation ApplicationDelegate
|
2014-09-20 21:31:03 +00:00
|
|
|
|
2016-10-22 14:35:37 +00:00
|
|
|
namespace Platform {
|
|
|
|
|
|
|
|
void SetWatchingMediaKeys(bool watching) {
|
|
|
|
if (_sharedDelegate) {
|
2017-04-12 11:58:37 +00:00
|
|
|
[_sharedDelegate setWatchingMediaKeys:watching];
|
2016-10-22 14:35:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-24 08:28:11 +00:00
|
|
|
void SetApplicationIcon(const QIcon &icon) {
|
2019-04-29 13:41:51 +00:00
|
|
|
NSImage *image = nil;
|
|
|
|
if (!icon.isNull()) {
|
|
|
|
auto pixmap = icon.pixmap(1024, 1024);
|
2018-10-24 08:28:11 +00:00
|
|
|
pixmap.setDevicePixelRatio(cRetinaFactor());
|
2020-10-27 10:32:09 +00:00
|
|
|
image = Q2NSImage(pixmap.toImage());
|
2019-04-29 13:41:51 +00:00
|
|
|
}
|
|
|
|
[[NSApplication sharedApplication] setApplicationIconImage:image];
|
|
|
|
}
|
|
|
|
|
2017-05-02 07:25:20 +00:00
|
|
|
} // namespace Platform
|
|
|
|
|
2016-11-08 14:07:25 +00:00
|
|
|
bool objc_handleMediaKeyEvent(void *ev) {
|
|
|
|
auto e = reinterpret_cast<NSEvent*>(ev);
|
2016-11-28 15:45:07 +00:00
|
|
|
|
2016-10-17 14:57:14 +00:00
|
|
|
int keyCode = (([e data1] & 0xFFFF0000) >> 16);
|
|
|
|
int keyFlags = ([e data1] & 0x0000FFFF);
|
|
|
|
int keyState = (((keyFlags & 0xFF00) >> 8)) == 0xA;
|
|
|
|
int keyRepeat = (keyFlags & 0x1);
|
|
|
|
|
2016-10-22 14:35:37 +00:00
|
|
|
if (!_sharedDelegate || ![_sharedDelegate isWatchingMediaKeys]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-17 14:57:14 +00:00
|
|
|
switch (keyCode) {
|
|
|
|
case NX_KEYTYPE_PLAY:
|
|
|
|
if (keyState == 0) { // Play pressed and released
|
2017-01-24 21:24:39 +00:00
|
|
|
Media::Player::instance()->playPause();
|
2016-10-17 14:57:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_KEYTYPE_FAST:
|
|
|
|
if (keyState == 0) { // Next pressed and released
|
2017-01-24 21:24:39 +00:00
|
|
|
Media::Player::instance()->next();
|
2016-10-17 14:57:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_KEYTYPE_REWIND:
|
|
|
|
if (keyState == 0) { // Previous pressed and released
|
2017-01-24 21:24:39 +00:00
|
|
|
Media::Player::instance()->previous();
|
2016-10-17 14:57:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-06-25 07:25:55 +00:00
|
|
|
void objc_debugShowAlert(const QString &str) {
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
2015-07-13 17:55:59 +00:00
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
[[NSAlert alertWithMessageText:@"Debug Message" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@", Q2NSString(str)] runModal];
|
2014-06-14 19:32:11 +00:00
|
|
|
|
2016-10-02 15:44:54 +00:00
|
|
|
}
|
2014-06-14 19:32:11 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 07:25:55 +00:00
|
|
|
void objc_outputDebugString(const QString &str) {
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
|
|
|
|
NSLog(@"%@", Q2NSString(str));
|
|
|
|
|
|
|
|
}
|
2014-06-14 19:32:11 +00:00
|
|
|
}
|
|
|
|
|
2014-09-20 21:31:03 +00:00
|
|
|
void objc_start() {
|
2019-11-05 11:27:21 +00:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
|
2019-10-11 06:32:26 +00:00
|
|
|
// Patch: Fix macOS regression. On 10.14.4, it crashes on GPU switches.
|
|
|
|
// See https://bugreports.qt.io/browse/QTCREATORBUG-22215
|
|
|
|
const auto version = QOperatingSystemVersion::current();
|
|
|
|
if (version.majorVersion() == 10
|
|
|
|
&& version.minorVersion() == 14
|
|
|
|
&& version.microVersion() == 4) {
|
|
|
|
qputenv("QT_MAC_PRO_WEBENGINE_WORKAROUND", "1");
|
|
|
|
}
|
2019-11-05 11:27:21 +00:00
|
|
|
#endif // Qt 5.9.0
|
2019-10-11 06:32:26 +00:00
|
|
|
|
2014-09-20 21:31:03 +00:00
|
|
|
_sharedDelegate = [[ApplicationDelegate alloc] init];
|
|
|
|
[[NSApplication sharedApplication] setDelegate:_sharedDelegate];
|
2014-11-12 20:30:26 +00:00
|
|
|
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: _sharedDelegate
|
|
|
|
selector: @selector(receiveWakeNote:)
|
|
|
|
name: NSWorkspaceDidWakeNotification object: NULL];
|
2014-09-20 21:31:03 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 11:58:37 +00:00
|
|
|
void objc_ignoreApplicationActivationRightNow() {
|
|
|
|
if (_sharedDelegate) {
|
|
|
|
[_sharedDelegate ignoreApplicationActivationRightNow];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-26 17:34:52 +00:00
|
|
|
namespace {
|
|
|
|
NSURL *_downloadPathUrl = nil;
|
|
|
|
}
|
|
|
|
|
2014-06-18 18:37:44 +00:00
|
|
|
void objc_finish() {
|
2014-09-20 21:31:03 +00:00
|
|
|
[_sharedDelegate release];
|
2017-04-12 11:58:37 +00:00
|
|
|
_sharedDelegate = nil;
|
2015-11-26 17:34:52 +00:00
|
|
|
if (_downloadPathUrl) {
|
|
|
|
[_downloadPathUrl stopAccessingSecurityScopedResource];
|
|
|
|
_downloadPathUrl = nil;
|
|
|
|
}
|
2014-06-18 18:37:44 +00:00
|
|
|
}
|
2014-06-25 07:25:55 +00:00
|
|
|
|
2015-08-12 18:02:20 +00:00
|
|
|
void objc_activateProgram(WId winId) {
|
2014-06-25 07:25:55 +00:00
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
2015-08-12 18:02:20 +00:00
|
|
|
if (winId) {
|
|
|
|
NSWindow *w = [reinterpret_cast<NSView*>(winId) window];
|
|
|
|
[w makeKeyAndOrderFront:NSApp];
|
|
|
|
}
|
2014-06-25 07:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool objc_moveFile(const QString &from, const QString &to) {
|
2016-10-02 15:44:54 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
|
|
|
|
NSString *f = Q2NSString(from), *t = Q2NSString(to);
|
2014-06-25 07:25:55 +00:00
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:t]) {
|
|
|
|
NSData *data = [NSData dataWithContentsOfFile:f];
|
|
|
|
if (data) {
|
|
|
|
if ([data writeToFile:t atomically:YES]) {
|
|
|
|
if ([[NSFileManager defaultManager] removeItemAtPath:f error:nil]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ([[NSFileManager defaultManager] moveItemAtPath:f toPath:t error:nil]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-10-02 15:44:54 +00:00
|
|
|
|
|
|
|
}
|
2014-06-25 07:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-30 18:24:18 +00:00
|
|
|
double objc_appkitVersion() {
|
|
|
|
return NSAppKitVersionNumber;
|
|
|
|
}
|
|
|
|
|
2016-08-31 17:58:46 +00:00
|
|
|
QString objc_documentsPath() {
|
|
|
|
NSURL *url = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
|
|
|
|
if (url) {
|
|
|
|
return QString::fromUtf8([[url path] fileSystemRepresentation]) + '/';
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2014-06-25 07:25:55 +00:00
|
|
|
QString objc_appDataPath() {
|
|
|
|
NSURL *url = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
|
|
|
|
if (url) {
|
2020-01-29 09:44:37 +00:00
|
|
|
return QString::fromUtf8([[url path] fileSystemRepresentation]) + '/' + AppName.utf16() + '/';
|
2014-06-25 07:25:55 +00:00
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2015-11-26 17:34:52 +00:00
|
|
|
QByteArray objc_downloadPathBookmark(const QString &path) {
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifndef OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
return QByteArray();
|
2016-08-31 17:58:46 +00:00
|
|
|
#else // OS_MAC_STORE
|
|
|
|
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:path.toUtf8().constData()] isDirectory:YES];
|
|
|
|
if (!url) return QByteArray();
|
|
|
|
|
|
|
|
NSError *error = nil;
|
|
|
|
NSData *data = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:&error];
|
|
|
|
return data ? QByteArray::fromNSData(data) : QByteArray();
|
|
|
|
#endif // OS_MAC_STORE
|
2015-11-26 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void objc_downloadPathEnableAccess(const QByteArray &bookmark) {
|
2016-08-31 17:58:46 +00:00
|
|
|
#ifdef OS_MAC_STORE
|
|
|
|
if (bookmark.isEmpty()) return;
|
|
|
|
|
|
|
|
BOOL isStale = NO;
|
|
|
|
NSError *error = nil;
|
|
|
|
NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark.toNSData() options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&isStale error:&error];
|
|
|
|
if (!url) return;
|
|
|
|
|
|
|
|
if ([url startAccessingSecurityScopedResource]) {
|
|
|
|
if (_downloadPathUrl) {
|
|
|
|
[_downloadPathUrl stopAccessingSecurityScopedResource];
|
|
|
|
}
|
2019-04-13 15:49:13 +00:00
|
|
|
_downloadPathUrl = [url retain];
|
2016-08-31 17:58:46 +00:00
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().settings().setDownloadPath(NS2QString([_downloadPathUrl path]) + '/');
|
2016-08-31 17:58:46 +00:00
|
|
|
if (isStale) {
|
|
|
|
NSData *data = [_downloadPathUrl bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope includingResourceValuesForKeys:nil relativeToURL:nil error:&error];
|
|
|
|
if (data) {
|
2020-06-18 18:04:16 +00:00
|
|
|
Core::App().settings().setDownloadPathBookmark(QByteArray::fromNSData(data));
|
|
|
|
Local::writeSettings();
|
2016-08-31 17:58:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // OS_MAC_STORE
|
|
|
|
}
|