Get menubar color / dark mode in Monterey - objective-c

How do we get what the text color (black/white) of the menubar is in Monterey ?
I'm developing an app with a menubar icon, in previous versions of OSX I could determine whether I should be drawing black or white icons by getting dark mode status with this code:
- (BOOL )amiindarkmode {
if ( [[NSUserDefaults standardUserDefaults] stringForKey:#"AppleInterfaceStyle"] != nil )
return YES ;
return NO ;
}
However in OS X. 12.6 (Monterey) the color of the menubar seems independant of dark mode and just flips for day / night time regardless.
Is there a new variable in OSX 12.6 I need to monitor ?

Related

Hide Notch grey background when launching splash screen

For react-native app on Android For the devices with Notch -
I am able to use full screen mode on all screens except Splash screen by this code : This code basically uses full screen even behind the notch.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
getWindow().setAttributes(layoutParams);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
I need to use full screen mode on Splash screen as well. It shows grey / default bg color as shown below.

Mac OSX: How to detect that NO window is selected?

I am working on the app which resizes the selected window.
It works successfully when any window is selected. But crashes when no window is selected.
Currently fetching front most window from the following code.
AXUIElementCopyAttributeValue(frontMostApp, kAXFocusedWindowAttribute, (CFTypeRef *)&frontMostWindow);
But how to detect that control is on desktop or all the windows are inactive.
AXUIElementCopyAttributeValue() returns AXError, so you can catch it and then check what happened.
AXError error = AXUIElementCopyAttributeValue(frontMostApp, kAXFocusedWindowAttribute, (CFTypeRef *)&frontMostWindow);
if (error != kAXErrorSuccess) {
//solve problems here
}
In your specific case there is a value of an error returned: kAXErrorNoValue = -25212
You can use AppleScript to do this. When creating a new project in Xcode, you can choose "Cocoa-AppleScript" as your app type by going under OS X > Other to make an app that has both Obj-C and AppleScript. You can use this code to make the app that has focus do something:
tell current app to ...
You can use this code to change the size of the window
set the bounds of the front window to {x, y, x + width, y + height}
Here, x and y are the distance from the top-left corner.
You can add this to your project and modify the size of the window that is currently at the front. This means that the frontmost window of the app with focus will be resized. This is a working and fully interactive example:
set theWindows to the windows of the current application
if the length of theWindows is 0 then
display alert "There are no windows to resize"
else
display dialog "Enter x" default answer ""
set x to text returned of result as number
display dialog "Enter y" default answer ""
set y to text returned of result as number
display dialog "Enter width" default answer ""
set width to text returned of result as number
set width to (x + width)
display dialog "Enter height" default answer ""
set height to text returned of result as number
set height to (y + height)
tell current application to set the bounds of the front window to {x, y, width, height}
end if
In Yosemite you can create apps that have nothing at their core but AppleScript with the "Script Editor" application. In Mavericks and older systems the app is called "AppleScript Editor". If you need Objective-C for other parts of your app you can create a Cocoa-AppleScript program using the method I described earlier.

Titanium View Under iPhone Status Bar

I'm very noob in Titanium Mobile.
When I create a new window the content of it goes through the iPhone Status bar (hour, signal and battery icons go on the content of my window).
Is there a fast way to check if the App is run by an iPhone and set the window to start under the status bar? (I mean in alloy way).
"#mainWindow": {
fullscreen: false,
statusBarStyle:Titanium.UI.iPhone.StatusBar.DEFAULT
}
I tried this but it did not work, but if I set in the previous code the property fullscreen to true the status bar disappears.
I suppose you want use this app at iOS 7 (title question).
"#mainWindow": {
fullscreen: false,
statusBarStyle: Ti.UI.iPhone.StatusBar.DEFAULT
width: Ti.Platform.DisplayCaps.getPlatformWidth(),
height: (Ti.Platform.DisplayCaps.getDpi() === 320 || Ti.Platform.DisplayCaps.getDpi() === 260) ? Ti.Platform.DisplayCaps.getPlatformHeight() - 40 : Ti.Platform.DisplayCaps.getPlatformHeight() - 20,
top: (Ti.Platform.DisplayCaps.getDpi() === 320 || Ti.Platform.DisplayCaps.getDpi() === 260) ? 40 : 20
}
The MainWindow Top or View where you add all UI Elements must have top 40 (retina) or 20.
This is the height of StatusBar on iOS. If you want use this app at iOS version below 7.0, top is 0.

How to handle various view states in Windows 8.1 store app

I have windows 8.0 code and I had handled the UI for ViewStates like Portrait,Landscape, filled and Snapped. But with windows 8.1 a Viewer can move the app into any size. how do i handle the UI in this case. Currently i am doing it like this.
private void QuestionPage_SizeChanged(object sender, SizeChangedEventArgs e)
{
ApplicationViewState currentState = Windows.UI.ViewManagement.ApplicationView.Value;
if (currentState.Equals(ApplicationViewState.Snapped))
{
VisualStateManager.GoToState(this, "Snapped", false);
}
else if (currentState.Equals(ApplicationViewState.FullScreenLandscape))
{
VisualStateManager.GoToState(this, "FullScreenLandscape", false);
}
else if (currentState.Equals(ApplicationViewState.Filled))
{
VisualStateManager.GoToState(this, "Filled", false);
}
else if (currentState.Equals(ApplicationViewState.FullScreenPortrait))
{
VisualStateManager.GoToState(this, "FullScreenPortrait", false);
}
}
Firstly, you need to decide how to categorize your sizes. We decided to go with the following:
Default - landscape full screen.
Portrait - portrait full screen.
Small - snapped/resized to 500 - 683 wide, vertical orientation
Medium - snapped/resized to 684 wide and above, vertical orientation
So basically, the small and medium sizes are a vertical layout, as the height is bigger than the width. When the Medium width becomes larger than its height, then it would be the default landscape size.
We use:DisplayOrientations CurrentOrientation = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().CurrentOrientation; instead of ApplicationViewState for SizeChangedEventArgs.
Then define the sizes as follows:
//Small Size
if (e.NewSize.Width <= 683
&& (CurrentOrientation == DisplayOrientations.Landscape || CurrentOrientation == DisplayOrientations.LandscapeFlipped || CurrentOrientation == DisplayOrientations.None))
You can then play and define which ever sizes you would like.
Instead of basing your layout on ApplicationViewState - make it depend on size and aspect ratio of the window. Think how users would use your app and what layout would work best in these cases. Maybe one layout would be fine or maybe you might want to switch a GridView layout into a ListView one when the window width is smaller than some value - e.g. 500px. Think what's most comfortable to use in these cases. At the very least - test that the layout doesn't fall apart when you resize the app.

Mountain Lion: Launching App by dragging files on its Icon causes weird start-up-delay and other problems in the process

A quick way to reproduce this (ML, Xcode 441):
- New Cocoa Application (all project options "off")
- add a Document Type with "Role > Viewer" and "Extensions > *"
- add the following code to the appDelegate:
- (BOOL)application:(NSApplication *)sender openFile:(NSString *)path
{
NSLog(#"%#", path);
return YES;
}
> "Run" ... -> Quick launchtime, and the window is visible immediately.
> Now launch the App by dragging a file on its icon ... -> Quick launch (-applicationDidFinishLaunching:), but it takes almost five seconds for the window to appear!
What happens in these 5 seconds?
A simple workaround SEEMS to be something like this:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[_window makeKeyAndOrderFront:self];
}
Now the window is immediately visible even when launching the App by dragging files on its icon.
BUT there are other problems that this workaround does not fix:
- Now in MainMenu.xib set the Window to "Full Screen > Primary Window"
> "Build"
> launch the App by dragging a file on its icon, wait 5 seconds, enter "Full Screen"-mode -> no problems, no redraw issues (EXIT "Full Screen", quit)
> launch the App by dragging a file on its icon, IMMEDIATELY enter "Full Screen"-mode -> display problems: there is no linen background, but instead the window in fullscreen-state is visible as the background behind the zooming animation!? (stay in "Full Screen", quit)
> launch the app by doubleclick -> without problems the app is back in "Full Screen"-mode (stay in "Full Screen", quit)
> launch the App by dragging a file on its icon -> The App-Window enters fullscreen-state (-windowDidEnterFullScreen:), but there is no "space-change" so the fullscreen-window is not visible. And its NOT possible to switch to this space immediately (e.g. by clicking the App-Icon). You have to wait the 5 seconds to be able to do this!
So it looks like even these Fullscreen-problems have to do with the 5 second-delay we saw at the beginning!?
Is this a Mountain Lion Bug (Seems not to happen in Lion this way) or is this expected behaviour? Am I missing something really obvious? Is there a workaround?
I need my App to reliably enter FullScreen-mode even on App-launch! Is there a way to achieve this?
Thanks a lot!