How to create custom ActivationPolicy of the app? - swift

Original activation policies is:
// The application is an ordinary app that appears in the Dock and may
// have a user interface.
NSApp.setActivationPolicy(.regular)
// The application does not appear in the Dock and does not have a menu
// bar, but it may be activated programmatically or by clicking on one
// of its windows.
NSApp.setActivationPolicy(.accessory)
// The application does not appear in the Dock and may not create
// windows or be activated.
NSApp.setActivationPolicy(.prohibited)
I need combination of all of those policies:
to display icon in dock like .regular
to do not have menubar like .acessory
[resolved] to display window above fullscreen apps like .prohibited
[resolved] to register window notifications like in .regular and .acessory
[resolved] to have ability to open "Preferences" window like in .regular and .acessory---
How can I create own ActivationPolicy or how can I controll those parameters without "policy" ?
upd: part of problems resolved here:
How to locate window over all of apps (even if they are fullscreen-ed)

Related

Is it possible to write a custom TouchBar app for an existing application?

I have tried looking for an answer to this but can't seem to see anything about it.
I have a piece of software on my laptop (not written by me), that I want to customise. Some of the tasks I do are very repetitive, and could be simplified by just pressing a button on the Touch Bar that executes a number of commands.
Is it possible to write a Touch Bar app that either:
1) Customises the application's original TouchBar app (for which there is none)
2) Runs only when that application is running, and hides when the application is out of focus
Thanks
I believe BetterTouchTool can do that.
Also in the "App Specific" button you can customise when to hide system touch bar and when to show it again

Custom button for toolbar Eclipse RCP Application

I am currently working on a web browser application using Eclipse e4.
I want to put on the toolbar a toggle button for saving my favorites url's.
I want it to be like in Google Chrome , a star which gets the yellow color when it's pressed(the link was added to favorites).
How can I do this?
Should I use for this the Application.e4xmi ?
You can use the Application.e4xmi if this is a tool bar for a Window or a Part. You would use a 'Handled Tool Item' in the tool bar.
The Application.e4xmi does not provide a way to set separate icons for the selected and normal states of a tool item so you will have to do this in the handler class. Something like:
#Execute
public void execute(MToolItem mitem)
{
if (mitem.isSelected())
mitem.setIconURI("platform:/plugin/your.plugin.id/icons/selectedimage.png");
else
mitem.setIconURI("platform:/plugin/your.plugin.id/icons/unselectedimage.png");
// TODO other code
}

How to hide Open and Save document features in a Document Based application?

Like Safari app, in a macOS Swift project I would like to let users to open more than a window and possibly use tabbed browsing to switch from a window to another. The app starts with a blank window and don't need to save or open documents.
A Document Based application seems perfect to me for handle more than a window but I don't want users have to handle documents. How can I disable or hide, if possible, the Open and Save document features?
Edit: if possible, I would like to disable this popup also:
It is very simple - just remove (delete) the Open, Open Recent..., Save, Save as... menu items from the menu XIB. If you don't want a title bar, simply untick the "Title" checkbox for the window in the XIB, though that makes the window difficult to move.
If you have a title bar, to override "Untitled", you could
override var displayName: String! {
get {
return "Anything you like, even \"\""
}
set {
}
}
however that would still allow access to the save as menu through the chevron. To suppress that, you need an NSWindowDelegate Docs
window(_:shouldPopUpDocumentPathMenu:)
Asks the delegate whether the window displays the title pop-up menu in response to a Command-click or Control-click on its title.
Just add autosavesInPlace at true

Dock "Turn Hiding On" programmatically from within an app

If you secondary-click on the Dock you can click the Turn Hiding On option to automatically hide the Dock. Alternatively, you can go to System Preferences > Dock and click the Automatically hide and show the Dock.
I want to mimic that functionality from within an app I am making (which is basically a status bar icon app) and preferably in Swift.
The code I have written so far to turn on the Dock Automatic Hiding functionality is the following:
// Update the value for key "autohide" in com.apple.dock.plist, located in ~/Library/Preferences/.
var dict = NSUserDefaults.standardUserDefaults().persistentDomainForName("com.apple.dock")
dict.updateValue(true, forKey: "autohide")
NSUserDefaults.standardUserDefaults().setPersistentDomain(dict, forName: "com.apple.dock")
// Send notification to the OS.
dispatch_async(dispatch_get_main_queue()) {
CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(), "com.apple.dock.prefchanged", nil, nil, true)
}
The first part of the code updates a value in a plist file and I have confirmed that that is working. The second part sends a notification to the OS to tell it that a value has been changed in that plist, which I have also confirmed to be working.
However, these two things are not making the Dock hide, making me believe I need to do something else. Or made my approach to the problem is wrong? How do I make the Dock start hiding?
PS: I have read something about a private, undocumented API called CoreDock, but I would like to avoid going that way, as it may cause many problems...
Almost certainly better to use AppleScript or the Scripting Bridge to do this. The following script turns Dock autohiding on:
tell application "System Events"
set autohide of dock preferences to true
end tell
You can run that using NSAppleScript.

How to create Android app WITHOUTH action bar?

I can not create an android app with an SDK < 14 (4.0) because all of the templates (including the so-called "Blank") include the "Action Bar", which is a 14+ feature.
How do I create an app WITHOUT an action bar? Does somebody have an old template for Blank without an Action Bar?
You can instantiate the Action Bar object and using the method hide() you will be able to hide it.
final ActionBar bar = getActionBar();
And from the documentation:
Instead of calling this function directly, you can also cause an
ActionBar using the overlay feature to hide through
View.SYSTEM_UI_FLAG_FULLSCREEN. Hiding the ActionBar through this
system UI flag allows you to more seamlessly hide it in conjunction
with other screen decorations
Hope it helps