Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/src/common/cocoa_tools.h
4212 views
1
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]>
2
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
3
4
#include "types.h"
5
6
#include <optional>
7
#include <span>
8
#include <string>
9
#include <string_view>
10
11
class Error;
12
13
#ifdef __OBJC__
14
#import <AppKit/AppKit.h>
15
#import <Cocoa/Cocoa.h>
16
17
namespace CocoaTools {
18
NSString* StringViewToNSString(std::string_view str);
19
void NSErrorToErrorObject(Error* errptr, std::string_view message, NSError* error);
20
21
/// Converts NSError to a human-readable string.
22
std::string NSErrorToString(NSError* error);
23
} // namespace CocoaTools
24
25
#endif
26
27
namespace CocoaTools {
28
// Converts to Mach timebase.
29
u64 ConvertMachTimeBaseToNanoseconds(u64 ns);
30
u64 ConvertNanosecondsToMachTimeBase(u64 ns);
31
32
/// Moves a file from one location to another, using NSFileManager.
33
bool MoveFile(const char* source, const char* destination, Error* error);
34
35
/// Returns the bundle path.
36
std::optional<std::string> GetBundlePath();
37
38
/// Get the bundle path to the actual application without any translocation fun
39
std::optional<std::string> GetNonTranslocatedBundlePath();
40
41
/// Launch the given application once this one quits
42
bool DelayedLaunch(std::string_view file, std::span<const std::string_view> args = {});
43
} // namespace CocoaTools
44
45