Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macOS build #225

Merged
merged 4 commits into from
Sep 7, 2024
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
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download dbip database
run: wget -nv -O- "https://download.db-ip.com/free/dbip-country-lite-2024-04.mmdb.gz" | zcat > dbip.mmdb
run: wget -nv -O- "https://download.db-ip.com/free/dbip-country-lite-2024-09.mmdb.gz" | zcat > dbip.mmdb
- uses: actions/upload-artifact@v3
with:
name: dbip
Expand Down Expand Up @@ -62,6 +62,10 @@ jobs:
if: matrix.platform.rust_target == 'aarch64-apple-darwin'
run: rustup target add aarch64-apple-darwin

- name: "Setup Rust"
if: matrix.platform.rust_target == 'x86_64-apple-darwin'
run: rustup target add x86_64-apple-darwin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this does something? Isn't that the default arch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late response, must have missed a notification somehwere. But I added this because I believe the default has changed for runners. At least in this action output it says: failed to build app: Target x86_64-apple-darwin is not installed (installed targets: aarch64-apple-darwin).. So just to be sure we have build-targets available independent of which host-architecture we run on, I added the second action.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, rust probably changed which arch supports gets installed by default on arm macs.
Thanks.


- uses: Swatinem/rust-cache@v2
with:
shared-key: ${{ matrix.platform.rust_target }}
Expand All @@ -76,7 +80,7 @@ jobs:
- name: install npm packages
run: npm ci

- uses: qu1ck/action-tauri-build@5c69c9fdbb4231a738b4a668a2caddf6af45eab8
- uses: JonasKruckenberg/tauri-build@v1
id: tauri_build
with:
target: ${{ matrix.platform.rust_target }}
Expand Down
29 changes: 15 additions & 14 deletions src-tauri/src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ use std::{
use objc2::{
class, declare_class,
ffi::NSInteger,
msg_send, msg_send_id,
mutability::Immutable,
msg_send, msg_send_id, mutability,
rc::Id,
runtime::{NSObject, Object},
sel, ClassType,
runtime::{AnyObject, NSObject},
sel, ClassType, DeclaredClass,
};
use once_cell::sync::OnceCell;
use tauri::{Menu, MenuItem, Submenu, CustomMenuItem};
use tauri::{CustomMenuItem, Menu, MenuItem, Submenu};

type THandler = OnceCell<Mutex<Box<dyn FnMut(Vec<String>) + Send + 'static>>>;

Expand All @@ -54,7 +53,7 @@ const EVENT_OPEN_DOCUMENTS: u32 = 0x6F646F63;
const EVENT_REOPEN_APP: u32 = 0x72617070;

// Adapted from https://github.com/mrmekon/fruitbasket/blob/aad14e400d710d1d46317c0d8c55ff742bfeaadd/src/osx.rs#L848
fn parse_event(event: *mut Object) -> Vec<String> {
fn parse_event(event: *mut AnyObject) -> Vec<String> {
if event as u64 == 0u64 {
return vec![];
}
Expand All @@ -64,9 +63,9 @@ fn parse_event(event: *mut Object) -> Vec<String> {

match (class, id) {
(GURL_EVENT_CLASS, EVENT_GET_URL) => {
let url: *mut Object =
let url: *mut AnyObject =
msg_send![event, paramDescriptorForKeyword: KEY_DIRECT_OBJECT];
let nsstring: *mut Object = msg_send![url, stringValue];
let nsstring: *mut AnyObject = msg_send![url, stringValue];
let cstr: *const i8 = msg_send![nsstring, UTF8String];

if !cstr.is_null() {
Expand All @@ -76,15 +75,15 @@ fn parse_event(event: *mut Object) -> Vec<String> {
}
}
(CORE_EVENT_CLASS, EVENT_OPEN_DOCUMENTS) => {
let documents: *mut Object =
let documents: *mut AnyObject =
msg_send![event, paramDescriptorForKeyword: KEY_DIRECT_OBJECT];
let count: NSInteger = msg_send![documents, numberOfItems];

let mut paths = Vec::<String>::new();

for i in 1..count + 1 {
let path: *mut Object = msg_send![documents, descriptorAtIndex: i];
let nsstring: *mut Object = msg_send![path, stringValue];
let path: *mut AnyObject = msg_send![documents, descriptorAtIndex: i];
let nsstring: *mut AnyObject = msg_send![path, stringValue];
let cstr: *const i8 = msg_send![nsstring, UTF8String];

if !cstr.is_null() {
Expand All @@ -108,13 +107,15 @@ declare_class!(

unsafe impl ClassType for Handler {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = mutability::Immutable;
const NAME: &'static str = "TauriPluginDeepLinkHandler";
}

impl DeclaredClass for Handler {}

unsafe impl Handler {
#[method(handleEvent:withReplyEvent:)]
fn handle_event(&self, event: *mut Object, _replace: *const Object) {
fn handle_event(&self, event: *mut AnyObject, _replace: *const AnyObject) {
let s = parse_event(event);
let mut cb = HANDLER.get().unwrap().lock().unwrap();
cb(s);
Expand Down Expand Up @@ -143,7 +144,7 @@ pub fn set_handler<F: FnMut(Vec<String>) + Send + 'static>(handler: F) -> Result

fn listen_apple_event(event_class: u32, event_id: u32) {
unsafe {
let event_manager: Id<Object> =
let event_manager: Id<AnyObject> =
msg_send_id![class!(NSAppleEventManager), sharedAppleEventManager];

let handler = Handler::new();
Expand Down
Loading