mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-20 11:35:56 +00:00
fix: config path error on mac
This commit is contained in:
parent
f1e24fe81a
commit
587c1f5872
4 changed files with 26 additions and 0 deletions
|
@ -163,6 +163,8 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
|||
set(QC_UTIL_SOURCES ${QC_UTIL_SOURCES}
|
||||
util/mousetap/cocoamousetap.h
|
||||
util/mousetap/cocoamousetap.mm
|
||||
util/path.h
|
||||
util/path.mm
|
||||
)
|
||||
endif()
|
||||
source_group(util FILES ${QC_UTIL_SOURCES})
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
#include <QDebug>
|
||||
|
||||
#include "config.h"
|
||||
#ifdef Q_OS_OSX
|
||||
#include "path.h"
|
||||
#endif
|
||||
|
||||
#define GROUP_COMMON "common"
|
||||
|
||||
|
@ -125,7 +128,15 @@ const QString &Config::getConfigPath()
|
|||
QFileInfo fileInfo(s_configPath);
|
||||
if (s_configPath.isEmpty() || !fileInfo.isDir()) {
|
||||
// default application dir
|
||||
// mac系统当从finder打开app时,默认工作目录不再是可执行程序的目录了,而是"/"
|
||||
// 而Qt的获取工作目录的api都依赖QCoreApplication的初始化,所以使用mac api获取当前目录
|
||||
#ifdef Q_OS_OSX
|
||||
// get */QtScrcpy.app path
|
||||
s_configPath = Path::GetCurrentPath();
|
||||
s_configPath += "/Contents/MacOS/config";
|
||||
#else
|
||||
s_configPath = "config";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return s_configPath;
|
||||
|
|
6
QtScrcpy/util/path.h
Normal file
6
QtScrcpy/util/path.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
class Path {
|
||||
public:
|
||||
static const char* GetCurrentPath();
|
||||
};
|
7
QtScrcpy/util/path.mm
Normal file
7
QtScrcpy/util/path.mm
Normal file
|
@ -0,0 +1,7 @@
|
|||
#include "path.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
const char* Path::GetCurrentPath() {
|
||||
return [[[NSBundle mainBundle] bundlePath] UTF8String];
|
||||
}
|
Loading…
Add table
Reference in a new issue