Skip to content

Commit 9b44d1f

Browse files
committed
Initial commit
0 parents  commit 9b44d1f

File tree

27 files changed

+2742
-0
lines changed

27 files changed

+2742
-0
lines changed

Diff for: .clang-format

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
BasedOnStyle: LLVM
2+
ColumnLimit: 0
3+
DerivePointerBinding: true
4+
AllowShortIfStatementsOnASingleLine: true
5+
AllowShortBlocksOnASingleLine: true
6+
PointerAlignment: Left
7+
IndentCaseLabels: true

Diff for: .editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true
10+
11+
[Makefile]
12+
indent_style = tab

Diff for: .github/workflows/ci.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: macos-12
8+
9+
steps:
10+
- uses: actions/checkout@v1
11+
with:
12+
fetch-depth: 1
13+
- name: example
14+
run: make -C example
15+
- name: tests
16+
run: make -C tests

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

Diff for: .markdownlint.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"MD013": false,
3+
"MD030": {
4+
"ol_single": 2,
5+
"ol_multi": 2
6+
},
7+
"MD033": {
8+
"allowed_elements": ["br"]
9+
},
10+
"MD041": false
11+
}

Diff for: .vscode/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/browse.vc.db*

Diff for: .vscode/c_cpp_properties.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"browse": {
6+
"path": [
7+
"${workspaceFolder}/include",
8+
"${workspaceFolder}/tests/vendor/include",
9+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++",
10+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1"
11+
],
12+
"limitSymbolsToIncludedHeaders": true,
13+
"databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db"
14+
},
15+
"defines": [],
16+
"includePath": [
17+
"${workspaceFolder}/include",
18+
"${workspaceFolder}/tests/vendor/include",
19+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++",
20+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1"
21+
],
22+
"macFrameworkPath": []
23+
}
24+
],
25+
"version": 4
26+
}

Diff for: .vscode/settings.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"files.exclude": {
3+
"**/build/": true,
4+
"**/vendor/cget/": true,
5+
".vscode/browse.vc.*": true
6+
},
7+
"search.exclude": {
8+
"**/vendor/": true
9+
},
10+
"files.watcherExclude": {
11+
"**/build/**": true
12+
}
13+
}

Diff for: CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required (VERSION 3.9)
2+
3+
project(workspace)
4+
5+
install(
6+
DIRECTORY
7+
${CMAKE_CURRENT_LIST_DIR}/include
8+
${CMAKE_CURRENT_LIST_DIR}/src
9+
DESTINATION
10+
.
11+
)

Diff for: LICENSE.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Boost Software License - Version 1.0 - August 17th, 2003
2+
3+
Permission is hereby granted, free of charge, to any person or organization
4+
obtaining a copy of the software and accompanying documentation covered by
5+
this license (the "Software") to use, reproduce, display, distribute,
6+
execute, and transmit the Software, and to prepare derivative works of the
7+
Software, and to permit third-parties to whom the Software is furnished to
8+
do so, all subject to the following:
9+
10+
The copyright notices in the Software and this entire statement, including
11+
the above license grant, this restriction and the following disclaimer,
12+
must be included in all copies of the Software, in whole or in part, and
13+
all derivative works of the Software, unless such copies or derivative
14+
works are solely in the form of machine-executable object code generated by
15+
a source language processor.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.

Diff for: README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[![Build Status](https://github.com/pqrs-org/cpp-osx-workspace/workflows/CI/badge.svg)](https://github.com/pqrs-org/cpp-osx-workspace/actions)
2+
[![License](https://img.shields.io/badge/license-Boost%20Software%20License-blue.svg)](https://github.com/pqrs-org/cpp-osx-workspace/blob/main/LICENSE.md)
3+
4+
# cpp-osx-workspace
5+
6+
Utilities of `NSWorkspace`.
7+
8+
## Install
9+
10+
### Using package manager
11+
12+
You can install `include/pqrs` by using [cget](https://github.com/pfultz2/cget).
13+
14+
```shell
15+
cget install pqrs-org/cget-recipes
16+
cget install pqrs-org/cpp-osx-workspace
17+
```
18+
19+
And then, add `cget/src/pqrs/osx/workspace/impl/objc.m` to your project sources.
20+
21+
### Manual install
22+
23+
Copy `include/pqrs` directory into your include directory.
24+
25+
And then, add `src/pqrs/osx/workspace/impl/objc.m` to your project sources.

Diff for: example/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor/cget/cget.cmake
2+
/vendor/cget/pkg/pqrs-org__cget-recipes/
3+
/vendor/etc/cget/recipes/
4+
/vendor/**/pkgconfig/

Diff for: example/CMakeLists.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.9)
2+
3+
set(CMAKE_CXX_STANDARD 20)
4+
5+
add_compile_options(-Wall)
6+
add_compile_options(-Werror)
7+
add_compile_options(-O2)
8+
9+
project(example)
10+
11+
include_directories(${CMAKE_CURRENT_LIST_DIR}/../include)
12+
include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/vendor/include)
13+
14+
add_executable(
15+
example
16+
main.cpp
17+
../src/pqrs/osx/workspace/impl/objc.m
18+
)
19+
20+
target_link_libraries(
21+
example
22+
"-framework AppKit"
23+
)

Diff for: example/Makefile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
all:
2+
mkdir -p build \
3+
&& cd build \
4+
&& cmake .. \
5+
&& make
6+
7+
clean:
8+
rm -rf build
9+
10+
run:
11+
./build/example
12+
13+
update_vendor:
14+
rm -rf vendor
15+
cget install pqrs-org/cget-recipes --prefix vendor
16+
cget install -f cget-requirements.txt --prefix vendor

Diff for: example/cget-requirements.txt

Whitespace-only changes.

Diff for: example/main.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <iostream>
2+
#include <pqrs/osx/workspace.hpp>
3+
4+
int main(void) {
5+
std::cout << "Finder: "
6+
<< pqrs::osx::workspace::find_application_url_by_bundle_identifier("com.apple.Finder") << std::endl;
7+
8+
std::cout << "Safari: "
9+
<< pqrs::osx::workspace::find_application_url_by_bundle_identifier("com.apple.Safari") << std::endl;
10+
11+
std::cout << "Karabiner-Elements: "
12+
<< pqrs::osx::workspace::find_application_url_by_bundle_identifier("org.pqrs.Karabiner-Elements.Preferences") << std::endl;
13+
14+
std::cout << "NotFound: "
15+
<< pqrs::osx::workspace::find_application_url_by_bundle_identifier("org.pqrs.NotFound") << std::endl;
16+
17+
return 0;
18+
}

Diff for: include/pqrs/osx/workspace.hpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
// pqrs::osx::workspace v0.0
4+
5+
// (C) Copyright Takayama Fumihiko 2022.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See http://www.boost.org/LICENSE_1_0.txt)
8+
9+
#include "workspace/impl/objc.h"
10+
#include <string_view>
11+
12+
namespace pqrs {
13+
namespace osx {
14+
namespace workspace {
15+
16+
inline std::string find_application_url_by_bundle_identifier(const std::string_view& bundle_identifier) {
17+
auto url = pqrs_osx_workspace_find_application_url_by_bundle_identifier(bundle_identifier.data());
18+
if (url == nullptr) {
19+
return "";
20+
}
21+
22+
std::string result(url);
23+
free(url);
24+
return result;
25+
}
26+
27+
} // namespace workspace
28+
} // namespace osx
29+
} // namespace pqrs

Diff for: include/pqrs/osx/workspace/impl/objc.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
// (C) Copyright Takayama Fumihiko 2022.
4+
// Distributed under the Boost Software License, Version 1.0.
5+
// (See http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#ifdef __cplusplus
8+
extern "C" {
9+
#endif
10+
11+
// Do not use these functions directly.
12+
13+
char* pqrs_osx_workspace_find_application_url_by_bundle_identifier(const char* bundle_identifier);
14+
15+
#ifdef __cplusplus
16+
}
17+
#endif

Diff for: src/pqrs/osx/workspace/impl/objc.m

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// (C) Copyright Takayama Fumihiko 2022.
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// (See http://www.boost.org/LICENSE_1_0.txt)
4+
5+
#import <Cocoa/Cocoa.h>
6+
#import <pqrs/osx/workspace/impl/objc.h>
7+
8+
char* pqrs_osx_workspace_find_application_url_by_bundle_identifier(const char* bundle_identifier) {
9+
if (bundle_identifier == nil) {
10+
return nil;
11+
}
12+
13+
NSURL* url = [NSWorkspace.sharedWorkspace URLForApplicationWithBundleIdentifier:[NSString stringWithUTF8String:bundle_identifier]];
14+
if (url == nil) {
15+
return nil;
16+
}
17+
18+
const char* string = url.absoluteString.UTF8String;
19+
const size_t len = strlen(string);
20+
char* result = malloc(len + 1);
21+
snprintf(result, len + 1, "%s", string);
22+
return result;
23+
}

Diff for: tests/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor/cget/cget.cmake
2+
/vendor/cget/pkg/pqrs-org__cget-recipes/
3+
/vendor/etc/cget/recipes/
4+
/vendor/**/pkgconfig/

Diff for: tests/Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
all:
2+
@for d in `find * -type d`; do \
3+
if [ -f "$$d/CMakeLists.txt" ]; then \
4+
echo "[Test] $$d"; \
5+
make -C $$d || exit 1; \
6+
fi; \
7+
done
8+
9+
clean:
10+
@for d in `find * -type d`; do \
11+
if [ -f "$$d/CMakeLists.txt" ]; then \
12+
make -C $$d clean; \
13+
fi; \
14+
done
15+
16+
update_vendor:
17+
rm -rf vendor
18+
cget install pqrs-org/cget-recipes --prefix vendor
19+
cget install -f cget-requirements.txt --prefix vendor

Diff for: tests/cget-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
boost-ext/ut

Diff for: tests/src/CMakeLists.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required (VERSION 3.9)
2+
3+
set(CMAKE_CXX_STANDARD 20)
4+
5+
add_compile_options(-Wall)
6+
add_compile_options(-Werror)
7+
add_compile_options(-O2)
8+
9+
include_directories(${CMAKE_CURRENT_LIST_DIR}/../../include)
10+
include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../vendor/include)
11+
12+
project (test)
13+
14+
add_executable(
15+
test
16+
test.cpp
17+
../../src/pqrs/osx/workspace/impl/objc.m
18+
)
19+
20+
target_link_libraries(
21+
test
22+
"-framework AppKit"
23+
)

Diff for: tests/src/Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
all:
2+
mkdir -p build \
3+
&& cd build \
4+
&& cmake .. \
5+
&& make
6+
make run
7+
8+
clean:
9+
rm -rf build
10+
11+
run:
12+
./build/test

Diff for: tests/src/test.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <boost/ut.hpp>
2+
#include <pqrs/osx/workspace.hpp>
3+
4+
int main(void) {
5+
using namespace boost::ut;
6+
using namespace boost::ut::literals;
7+
using namespace std::literals::string_literals;
8+
9+
"find_application_url_by_bundle_identifier"_test = [] {
10+
expect(pqrs::osx::workspace::find_application_url_by_bundle_identifier("com.apple.Finder") == "file:///System/Library/CoreServices/Finder.app/"s);
11+
expect(pqrs::osx::workspace::find_application_url_by_bundle_identifier("org.pqrs.NotFound") == ""s);
12+
};
13+
14+
return 0;
15+
}

0 commit comments

Comments
 (0)