Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ jobs:
./scripts/code-sign.sh # after tar to avoid local signature in tarball

- name: Test
run: ctest --test-dir build/${{ matrix.arch }} --output-on-failure
run: |
ICON_DIR=~/Library/fcitx5/share/icons/hicolor/48x48/apps
mkdir -p $ICON_DIR && touch $ICON_DIR/fcitx_rime_deploy.png
ctest --test-dir build/${{ matrix.arch }} --output-on-failure

- name: Upload artifact
uses: actions/upload-artifact@v5
Expand Down
18 changes: 9 additions & 9 deletions macosnotifications/macosnotifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,22 @@ uint32_t Notifications::sendNotification(

// Record a notification item to store callbacks.
auto internalId = ++internalId_;
std::string externalId = appName + "-" + std::to_string(internalId_);
auto externalId = std::format("{}-{}", appName, internalId_);
NotificationItem item{externalId, internalId, actionCallback,
closedCallback};
itemTable_.insert(item);

// Find appIcon file.
static const std::vector<std::string> iconExtensions{".png"};
auto iconPath = iconTheme_->findIconPath(appIcon, 48, 1, iconExtensions);
auto iconPath = iconTheme_->findIconPath(appIcon, 48, 1, {".png"});

// Send the notification.
std::vector<const char *> cActionStrings;
auto actionsArray = swift::Array<swift::String>::init();
for (const auto &action : actions) {
cActionStrings.push_back(action.c_str());
actionsArray.append(action);
}
SwiftNotify::sendNotificationProxy(
externalId.c_str(), iconPath.c_str(), summary.c_str(), body.c_str(),
cActionStrings.data(), cActionStrings.size(), timeout);
SwiftNotify::sendNotification(externalId.c_str(), iconPath.c_str(),
summary.c_str(), body.c_str(), actionsArray,
timeout);

return internalId_;
}
Expand All @@ -79,7 +78,8 @@ void Notifications::showTip(const std::string &tipId,
if (hiddenNotifications_.count(tipId)) {
return;
}
std::vector<std::string> actions = {"dont-show", "Do not show again"};
std::vector<std::string> actions = {
"dont-show", translateDomain("fcitx5", "Do not show again")};
lastTipId_ = sendNotification(
appName, lastTipId_, appIcon, summary, body, actions, timeout,
[this, tipId](const std::string &action) {
Expand Down
42 changes: 8 additions & 34 deletions macosnotifications/notify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,40 +41,14 @@ public class NotificationDelegate: NSObject, UNUserNotificationCenterDelegate {
}
}

@_cdecl("sendNotificationProxy")
public func sendNotificationProxy(
_ identifier: UnsafePointer<CChar>,
_ iconPath: UnsafePointer<CChar>,
_ title: UnsafePointer<CChar>,
_ body: UnsafePointer<CChar>,
_ cActionStrings: UnsafePointer<UnsafePointer<CChar>>?,
_ cActionStringCount: Int,
_ timeout: Double
) {
var actionStrings: [String] = []
if let cActionStrings = cActionStrings {
for i in 0..<cActionStringCount {
actionStrings.append(String.init(cString: cActionStrings[i]))
}
}
sendNotification(
String.init(cString: identifier),
String.init(cString: iconPath),
String.init(cString: title),
String.init(cString: body),
actionStrings,
timeout
)
}

public func sendNotification(
_ identifier: String,
_ iconPath: String,
_ title: String, _ body: String,
_ actionStrings: [String],
_ timeout: Double
) {
DispatchQueue.main.async {
Task { @MainActor in
let categoryIdent = "ACTION_CATEGORY_\(identifier)"
var actions: [UNNotificationAction] = []
for i in stride(from: 0, to: actionStrings.count, by: 2) {
Expand Down Expand Up @@ -126,13 +100,13 @@ public func sendNotification(

let request = UNNotificationRequest(identifier: identifier, content: content, trigger: nil)

center.add(request) { error in
if let error = error {
FCITX_ERROR("Cannot send notification: \(error.localizedDescription)")
}
DispatchQueue.main.asyncAfter(deadline: .now() + timeout) {
closeNotification(identifier, NOTIFICATION_CLOSED_REASON_EXPIRY.rawValue)
}
do {
try await center.add(request)
} catch {
FCITX_ERROR("Cannot send notification: \(error.localizedDescription)")
}
DispatchQueue.main.asyncAfter(deadline: .now() + timeout) {
closeNotification(identifier, NOTIFICATION_CLOSED_REASON_EXPIRY.rawValue)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/fcitx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ void Fcitx::setupEnv() {
// plugins when Fcitx.app is reinstalled
user_prefix / "lib" / "fcitx5"});
std::string xdg_data_dirs = join_paths({
app_contents_path /
"share", // /Library/Input Methods/Fcitx5.app/Contents/share
user_prefix / "share" // ~/Library/fcitx5/share
});
std::string libime_model_dirs = join_paths({
Expand Down
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ fcitx5_import_addons(config-cpp
)
add_test(NAME config-cpp COMMAND config-cpp)

add_executable(icon-cpp testicon.cpp)
target_link_libraries(icon-cpp Fcitx5Objs SwiftFrontend)
add_test(NAME icon-cpp COMMAND icon-cpp)

# CustomPhrase .plist parser
add_executable(XmlParser testxmlparser.swift
${PROJECT_SOURCE_DIR}/src/config/xmlparser.swift
Expand Down
14 changes: 14 additions & 0 deletions tests/testicon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "fcitx/icontheme.h"
#include "../src/fcitx.h"

void test_find_icon() {
auto iconTheme = std::make_unique<fcitx::IconTheme>("hicolor");
auto path = iconTheme->findIconPath("fcitx_rime_deploy", 48, 1, {".png"});
FCITX_ASSERT(!path.empty());
}

int main() {
Fcitx::shared();
test_find_icon();
return 0;
}
Loading