chore: Added native macos handling, b=(no-bug), c=common

This commit is contained in:
mr. m
2025-05-12 23:31:48 +02:00
parent f58dbd71b6
commit 0b34cc3033
4 changed files with 42 additions and 20 deletions

View File

@@ -76,13 +76,17 @@ var gZenCommonActions = {
if (Services.zen.canShare()) {
button = {
id: 'zen-copy-current-url-button',
command: () =>
command: (event) => {
const buttonRect = event.target.getBoundingClientRect();
Services.zen.share(
Services.io.newURI(currentUrl),
"",
""
)
}
'',
'',
buttonRect.left - buttonRect.width / 2,
buttonRect.top + buttonRect.height
);
},
};
}
gZenUIManager.showToast('zen-copy-current-url-confirmation', { button });
}

View File

@@ -82,7 +82,7 @@ ZenCommonUtils::Share(nsIURI* url, const nsACString& title,
if (!IsSharingSupported()) {
return NS_OK; // We don't want to throw an error here
}
*_retval = ShareInternal(aWindow, url, title, text, aX, aY);
ShareInternal(aWindow, url, title, text, aX, aY);
return NS_OK;
}
@@ -92,7 +92,7 @@ void ZenCommonUtils::ShareInternal(nsCOMPtr<mozIDOMWindowProxy>& aWindow, nsIURI
// aWindow is valid.
#ifdef ZEN_CAN_SHARE_NATIVE
::nsZenNativeShareInternal(aWindow, url, title, text, aX, aY);
#else
#endif
}
auto ZenCommonUtils::IsSharingSupported() -> bool {

View File

@@ -3,23 +3,41 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ZenShareInternal.h"
#include "nsIWindowsUIUtils.h"
#include "nsCocoaUtils.h"
extern mozilla::LazyLogModule gCocoaUtilsLog;
#undef LOG
#define LOG(...) MOZ_LOG(gCocoaUtilsLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
@interface nsZenNativeShareInternal : NSObject
- (void)ShowNativeDialog:(nsCOMPtr<mozIDOMWindowProxy>& aWindow, nsIURI* aUrl,
const nsACString& aTitle, const nsACString& aText,
uint32_t aX, uint32_t aY) {
auto nsZenNativeShareInternal::ShowNativeDialog(
nsCOMPtr<mozIDOMWindowProxy>& aWindow, nsIURI* aUrl,
const nsACString& aTitle, const nsACString& aText,
uint32_t aX, uint32_t aY) const
-> void {
// Just use the URL since apple doesn't support sharing text
// and title in the share dialog
nsAutoCString pageUrlAsStringTemp;
if (aUrl) {
nsresult rv = aUrl->GetSpec(pageUrlAsStringTemp);
MOZ_ASSERT(NS_SUCCEEDED(rv));
mozilla::Unused << rv;
} else {
pageUrlAsStringTemp.SetIsVoid(true);
}
NSURL* pageUrl = nsCocoaUtils::ToNSURL(
NS_ConvertUTF8toUTF16(pageUrlAsStringTemp)
);
LOG("pageUrl: %s", pageUrlAsStringTemp.get());
if (!pageUrl || (![pageUrl.scheme isEqualToString:@"https"] &&
![pageUrl.scheme isEqualToString:@"http"])) {
return;
}
NSSharingServicePicker* sharingPicker =
[[NSSharingServicePicker alloc] initWithItems:@[ aUrl ]];
sharingPicker.delegate = self;
sharingPicker.showRelativeToRect:NSMakeRect(aX, aY, 0, 0)
ofView:(NSView*)aWindow
preferredEdge:NSMinYEdge;
[[NSSharingServicePicker alloc] initWithItems:@[ pageUrl ]];
// Create a rect for the sharing picker
NSRect rect = NSMakeRect(aX, aY, 0, 0);
[sharingPicker showRelativeToRect:rect];
}
@end

View File

@@ -5,7 +5,7 @@ XPIDL_SOURCES += [
EXPORTS.mozilla += [
"ZenCommonUtils.h",
"ZenShareInternal.h
"ZenShareInternal.h",
]
SOURCES += [