From: Ruben Beltran del Rio Date: Sat, 16 Mar 2024 16:08:52 +0000 (+0100) Subject: Add mac command X-Git-Tag: 3.0.0~11 X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli/commitdiff_plain/8d584ce755e90c6f5260f7f2828e5a294004148b Add mac command --- diff --git a/.gitignore b/.gitignore index 5bfe839..c58380d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ docs .env target distribution +*.tar.gz +*.tar.gz.sha256 diff --git a/Makefile b/Makefile index 61dc355..e2c1648 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ profile := dev target = $(shell rustc -vV | grep host | awk '{print $$2}') architectures := x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu app_name := lrc +long_app_name := lyricli default: build @@ -25,30 +26,43 @@ else endif deb: build +ifeq ($(findstring linux,$(target)),linux) @$(eval filename := $(app_name)-$(target)-$(channel)) @export $$(cat .env | xargs) > /dev/null 2>&1 && cargo deb --profile $(profile) --target $(target) mv target/$(target)/debian/*.deb $(filename).deb sha256sum $(filename).deb > $(filename).deb.sha256 - rsync -avz $(filename).deb deploy@conchos.unlimited.pizza:/srv/http/build.r.bdr.sh/$(app_name) - rsync -avz $(filename).deb.sha256 deploy@conchos.unlimited.pizza:/srv/http/build.r.bdr.sh/$(app_name) + rsync -avz $(filename).deb deploy@conchos.unlimited.pizza:/srv/http/build.r.bdr.sh/$(long_app_name) + rsync -avz $(filename).deb.sha256 deploy@conchos.unlimited.pizza:/srv/http/build.r.bdr.sh/$(long_app_name) +endif rpm: build +ifeq ($(findstring linux,$(target)),linux) @$(eval filename := $(app_name)-$(target)-$(channel)) @export $$(cat .env | xargs) > /dev/null 2>&1 && cargo generate-rpm --profile $(profile) --target $(target) mv target/$(target)/generate-rpm/*.rpm $(filename).rpm sha256sum $(filename).rpm > $(filename).rpm.sha256 - rsync -avz $(filename).rpm deploy@conchos.unlimited.pizza:/srv/http/build.r.bdr.sh/$(app_name) - rsync -avz $(filename).rpm.sha256 deploy@conchos.unlimited.pizza:/srv/http/build.r.bdr.sh/$(app_name) + rsync -avz $(filename).rpm deploy@conchos.unlimited.pizza:/srv/http/build.r.bdr.sh/$(long_app_name) + rsync -avz $(filename).rpm.sha256 deploy@conchos.unlimited.pizza:/srv/http/build.r.bdr.sh/$(long_app_name) +endif tar: build @$(eval filename := $(app_name)-$(target)-$(channel)) tar -czvf $(filename).tar.gz -C target/$(target)/$(profile)/ $(app_name) sha256sum $(filename).tar.gz > $(filename).tar.gz.sha256 - rsync -avz $(filename).tar.gz deploy@conchos.unlimited.pizza:/srv/http/build.r.bdr.sh/$(app_name) - rsync -avz $(filename).tar.gz.sha256 deploy@conchos.unlimited.pizza:/srv/http/build.r.bdr.sh/$(app_name) + rsync -avz $(filename).tar.gz deploy@conchos.unlimited.pizza:/srv/http/build.r.bdr.sh/$(long_app_name) + rsync -avz $(filename).tar.gz.sha256 deploy@conchos.unlimited.pizza:/srv/http/build.r.bdr.sh/$(long_app_name) package: $(architectures) +mac: +override architectures := x86_64-apple-darwin aarch64-apple-darwin +ifeq ($(tag),) + $(MAKE) -e profile=release -e architectures='$(architectures)' -e channel=unstable package +else + $(MAKE) -e profile=release -e architectures='$(architectures)' -e channel=$(tag) package +endif + + ci: ifeq ($(GIT_REF),refs/heads/main) $(MAKE) -e profile=release -e channel=unstable package diff --git a/src/sources/apple_music.rs b/src/sources/apple_music.rs index cb36f5c..06412b8 100644 --- a/src/sources/apple_music.rs +++ b/src/sources/apple_music.rs @@ -1,8 +1,8 @@ use std::ffi::CStr; use std::io::Result; -use cocoa::{base::nil, foundation::NSString}; -use objc::{class, msg_send, sel, sel_impl, runtime::Object}; +use cocoa::{base::{nil, id}, foundation::NSString}; +use objc::{class, msg_send, sel, sel_impl, runtime::{Class, Object}}; use objc_id::Id; use crate::Track; @@ -28,8 +28,17 @@ impl LyricsSource for AppleMusic { let app: Id = { let cls = class!(SBApplication); let bundle_identifier = NSString::alloc(nil).init_str("com.apple.Music"); - let app: *mut Object = msg_send![cls, applicationWithBundleIdentifier:bundle_identifier]; - Id::from_ptr(app) + + let workspace_class = Class::get("NSWorkspace").unwrap(); + let shared_workspace: id = msg_send![workspace_class, sharedWorkspace]; + let app_url: id = msg_send![shared_workspace, URLForApplicationWithBundleIdentifier:bundle_identifier]; + + if app_url != nil { + let app: *mut Object = msg_send![cls, applicationWithBundleIdentifier:bundle_identifier]; + Id::from_ptr(app) + } else { + return None + } }; if msg_send![app, isRunning] { diff --git a/src/sources/spotify.rs b/src/sources/spotify.rs index b23ea73..e4bf19c 100644 --- a/src/sources/spotify.rs +++ b/src/sources/spotify.rs @@ -1,8 +1,8 @@ use std::ffi::CStr; use std::io::Result; -use cocoa::{base::nil, foundation::NSString}; -use objc::{class, msg_send, sel, sel_impl, runtime::Object}; +use cocoa::{base::{nil, id}, foundation::NSString}; +use objc::{class, msg_send, sel, sel_impl, runtime::{Class, Object}}; use objc_id::Id; use crate::Track; @@ -28,8 +28,17 @@ impl LyricsSource for Spotify { let app: Id = { let cls = class!(SBApplication); let bundle_identifier = NSString::alloc(nil).init_str("com.spotify.Client"); - let app: *mut Object = msg_send![cls, applicationWithBundleIdentifier:bundle_identifier]; - Id::from_ptr(app) + + let workspace_class = Class::get("NSWorkspace").unwrap(); + let shared_workspace: id = msg_send![workspace_class, sharedWorkspace]; + let app_url: id = msg_send![shared_workspace, URLForApplicationWithBundleIdentifier:bundle_identifier]; + + if app_url != nil { + let app: *mut Object = msg_send![cls, applicationWithBundleIdentifier:bundle_identifier]; + Id::from_ptr(app) + } else { + return None + } }; if msg_send![app, isRunning] {