-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34c3008
commit c9b1973
Showing
14 changed files
with
390 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.DS_Store | ||
build | ||
*.tar.bz2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "fcitx5"] | ||
path = fcitx5 | ||
url = https://github.com/fcitx/fcitx5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This directory caches tarball of build dependencies | ||
(downloaded from [prebuilder](https://github.com/fcitx-contrib/fcitx5-ios-prebuilder/releases)), | ||
which will be extracted to `build/sysroot/usr`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
deps=( | ||
fmt | ||
libintl | ||
libuv | ||
) | ||
|
||
EXTRACT_DIR=build/sysroot/usr | ||
mkdir -p $EXTRACT_DIR | ||
|
||
if [[ $IOS_PLATFORM == "SIMULATOR" ]]; then | ||
POSTFIX=-$(uname -m) | ||
else | ||
POSTFIX="" | ||
fi | ||
|
||
for dep in "${deps[@]}"; do | ||
file=$dep$POSTFIX.tar.bz2 | ||
[[ -f cache/$file ]] || wget -P cache https://github.com/fcitx-contrib/fcitx5-ios-prebuilder/releases/download/latest/$file | ||
tar xjvf cache/$file -C $EXTRACT_DIR | ||
done | ||
|
||
sed -i '' "s|=/usr/include|=$(pwd)/$EXTRACT_DIR/include|" $EXTRACT_DIR/lib/pkgconfig/libuv.pc | ||
sed -i '' "s|-L\${libdir} -luv|$(pwd)/$EXTRACT_DIR/lib/libuv.a|" $EXTRACT_DIR/lib/pkgconfig/libuv.pc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
#include "nativestreambuf.h" | ||
#include <fcitx/instance.h> | ||
#include <thread> | ||
|
||
#include "fcitx.h" | ||
|
||
std::string getName() { | ||
return "f5i"; | ||
native_streambuf log_streambuf; | ||
std::unique_ptr<fcitx::Instance> instance; | ||
std::ostream stream(&log_streambuf); | ||
std::thread fcitx_thread; | ||
|
||
void startFcitx() { | ||
if (instance) { | ||
return; | ||
} | ||
fcitx::Log::setLogStream(stream); | ||
fcitx::Log::setLogRule("*=5,notimedate"); | ||
instance = std::make_unique<fcitx::Instance>(0, nullptr); | ||
fcitx_thread = std::thread([] { instance->exec(); }); | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
#include <string> | ||
|
||
std::string getName(); | ||
void startFcitx(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
* SPDX-FileCopyrightText: Copyright 2021-2023 Fcitx5 for Android Contributors | ||
* SPDX-License-Identifier: GPL-3.0-only | ||
* SPDX-FileCopyrightText: Copyright 2023 Qijia Liu | ||
*/ | ||
#ifndef FCITX5_IOS_NATIVESTREAMBUF_H | ||
#define FCITX5_IOS_NATIVESTREAMBUF_H | ||
|
||
#include <array> | ||
#include <iostream> | ||
#include <os/log.h> | ||
#include <streambuf> | ||
|
||
// Dynamic content is limited to 256B, see log.h | ||
template <std::size_t SIZE = 256> | ||
class native_streambuf : public std::streambuf { | ||
public: | ||
using Base = std::streambuf; | ||
using char_type = typename Base::char_type; | ||
using int_type = typename Base::int_type; | ||
|
||
native_streambuf() | ||
: _buffer{}, logger(os_log_create("org.fcitx.Fcitx5", "FcitxLog")) { | ||
Base::setp(_buffer.begin(), _buffer.end() - 1); | ||
} | ||
|
||
// buffer is full but current "line" of log hasn't finished | ||
int_type overflow(int_type ch) override { | ||
// append terminate character to the buffer (usually _buffer.end() when | ||
// overflow) | ||
*Base::pptr() = '\0'; | ||
const char *text = Base::pbase(); | ||
if (should_offset) { | ||
// it's the first write of this "line", guess priority | ||
update_log_priority(text[0]); | ||
// this write would skip first character | ||
write_log(text); | ||
// consequence write of this "line" should use same priority and | ||
// should not skip characters | ||
should_offset = false; | ||
} else { | ||
// it's not the first write of this "line", so just write | ||
write_log(text); | ||
} | ||
// mark buffer as available, since it's content has been written to | ||
// android log but we need to preserve the last position for '\0' in | ||
// case it overflows | ||
Base::setp(_buffer.begin(), _buffer.end() - 1); | ||
// write 'ch' as char if it's not eof | ||
if (!Base::traits_type::eq_int_type(ch, Base::traits_type::eof())) { | ||
const char_type c = Base::traits_type::to_char_type(ch); | ||
Base::xsputn(&c, 1); | ||
} | ||
return 0; | ||
} | ||
|
||
// current "line" of log has finished, and buffer is not full | ||
int_type sync() override { | ||
*Base::pptr() = '\0'; | ||
const char *text = Base::pbase(); | ||
if (should_offset) { | ||
// it's the first write of this "line", guess priority | ||
update_log_priority(text[0]); | ||
} | ||
write_log(text); | ||
// this "line" has finished and written to NS log, | ||
// reset state for next "line" | ||
should_offset = true; | ||
// mark buffer as available and preserve last position for '\0' | ||
Base::setp(_buffer.begin(), _buffer.end() - 1); | ||
return 0; | ||
} | ||
|
||
private: | ||
std::array<char_type, SIZE> _buffer; | ||
os_log_t logger; | ||
os_log_type_t prio; | ||
/** | ||
* whether the first character in buffer represents log level or not | ||
*/ | ||
bool should_offset = true; | ||
|
||
void update_log_priority(const char_type first) { | ||
switch (first) { | ||
case 'D': | ||
prio = OS_LOG_TYPE_DEBUG; | ||
break; | ||
case 'I': | ||
prio = OS_LOG_TYPE_INFO; | ||
break; | ||
case 'W': | ||
prio = OS_LOG_TYPE_ERROR; | ||
break; | ||
case 'E': | ||
case 'F': | ||
prio = OS_LOG_TYPE_FAULT; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
void write_log(const char_type *text) const { | ||
#ifdef NDEBUG | ||
if (prio != OS_LOG_TYPE_DEBUG) { | ||
std::cerr << text; | ||
} | ||
#else | ||
os_log_with_type(logger, prio, "%{public}s", | ||
text + (should_offset ? 1 : 0)); | ||
std::cerr << text; | ||
#endif | ||
} | ||
}; | ||
|
||
#endif // FCITX5_IOS_NATIVESTREAMBUF_H |
Oops, something went wrong.