Forum > Cocoa

NSApp.dockTile.setBadgeLabel issue in Monterey

(1/1)

trev:
This code works up to and including Big Sur, but fails to do anything with no system log errors in Monterey (12.0.1, 12.1 and 12.2).


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+}{$modeswitch objectivec2} interface uses  Classes, SysUtils, Forms, Dialogs, StdCtrls,  CocoaAll; type   { TForm1 }   TForm1 = Class(TForm)    Button1: TButton;    Button2: TButton;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin  // Display badge text on the dock tile (icon)  NSApp.dockTile.setBadgeLabel(NSStr('1'));end; procedure TForm1.Button2Click(Sender: TObject);begin  // Remove badge text from the dock tile (icon)  NSApp.dockTile.setBadgeLabel(Nil);end; end.
This pure FPC code still works in Monterey:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$mode objfpc}{$H+}{$modeswitch objectivec1} usesCocoaAll; type   TMyDelegate = objcclass(NSObject)   public      procedure BadgeButtonClick(sender :  id); message 'BadgeButtonClick:';      procedure UnBadgeButtonClick(sender :  id); message 'UnBadgeButtonClick:';   end; var   appName    : NSString;   window     : NSWindow;   myBadgeButton   : NSButton;   myUnBadgeButton : NSButton;   myDelegate : TMyDelegate; procedure TMyDelegate.BadgeButtonClick(sender :  id);begin   NSApp.dockTile.setBadgeLabel(NSStr('16'));end; procedure TMyDelegate.UnBadgeButtonClick(sender :  id);begin   NSApp.dockTile.setBadgeLabel(Nil);end; begin   // app and window creation   NSApp := NSApplication.sharedApplication;   NSApp.setActivationPolicy(NSApplicationActivationPolicyRegular);   appName := NSStr('Badger');   window := NSWindow.alloc.initWithContentRect_styleMask_backing_defer(NSMakeRect(0, 0, 200, 200),                    NSTitledWindowMask or NSClosableWindowMask or NSMiniaturizableWindowMask,                   NSBackingStoreBuffered, False);   myDelegate := TMyDelegate.alloc.init;    // badge button   myBadgeButton := NSButton.alloc.initWithFrame(NSMakeRect(50, 100, 100, 50));   window.contentView.addSubview(myBadgeButton);   myBadgeButton.setTitle(NSSTR('Badge'));   myBadgeButton.setButtonType(NSMomentaryLightButton);   myBadgeButton.setBezelStyle(NSRoundedBezelStyle);    // unbadge button   myUnBadgeButton := NSButton.alloc.initWithFrame(NSMakeRect(50, 60, 100, 50));   window.contentView.addSubview(myUnBadgeButton);   myUnBadgeButton.setTitle(NSSTR('UnBadge'));   myUnBadgeButton.setButtonType(NSMomentaryLightButton);   myUnBadgeButton.setBezelStyle(NSRoundedBezelStyle);    // badge button event handler   myBadgeButton.setTarget(myDelegate);   myBadgeButton.setAction(ObjCSelector(myDelegate.BadgeButtonClick));    // unbadge button event handler   myUnBadgeButton.setTarget(myDelegate);   myUnBadgeButton.setAction(ObjCSelector(myDelegate.UnBadgeButtonClick));    // Window showing and app running   window.center;   window.setTitle(appName);   window.makeKeyAndOrderFront(Nil);   NSApp.activateIgnoringOtherApps(True);   NSApp.run;end.
Any ideas why the Lazarus version of the code now fails?

trev:
Curiouser and curiouser.

I have two more or less identical (internal SSD size differs) 2018 Intel Mac minis running Monterey 12.3.1. On one system the badge appears, on the other system it does not. The same app was copied from the working one to the non-working one.

The badge also does not appear on my 2020 M1 Mac mini.

Comparing the two Intel systems is problematical because the working system is located 500Km away and there is no remote access.

Navigation

[0] Message Index

Go to full version