Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualize currently running applications by name #9

Merged
merged 10 commits into from
Mar 24, 2018

Conversation

LauraAubin
Copy link
Owner

@LauraAubin LauraAubin commented Mar 21, 2018

Part of this issue #5

What does this do?

This displays all of the currently running processes on the computer. This only displays them by name in list form. We can access more data such as PID with processIdentifier in a follow up PR.

image

How does it work?

Why do we have to declare class instances in the header?

NSWorkspace is a class that handles apps and file services. runningApplications is an instance property of this class. These cannot be used in the storyboard, so we put them in the header and pass pointers of these instances to the ProcessController.m file.

Component:

This makes use of the Table view component. The process list is generated from localizedName which returns the name of the application.

Attaching the controller to the component:

These are the steps I took to connect the functions in the ProcessController to the table component.

IMPORTANT NOTES:

  • Notice how I named the table column ProcessNamesColumn. This cannot happen. You must name the columns based on the data they are going to hold. So in our situation, we want to hold the names of the processes. If we look at the NSRunningApplication, you'll notice that it has a localizedName attribute. This returns the localized name of the application.

  • To access the currently running process data, you must use the NSWorkspace class. This will give you access to runningApplications, so you must use workspace.runningApplications on the content bindings (screenshots are wrong and should be corrected, this is case sensitive).

1. Add the Table view component to the scene.

The view stack should look as follows:


2. Create an object for the process controller:


3. Create an array controller:


4. Outlet arrayOfRunningProcesses to the newly created array controller

  • Right click on the Process Controller object


5. Bind the value of arrayOfRunningProcesses to the table column:

This is on the table column:

  • We are binding the table column to the array controller. Our array controller is now called "Array Of Running Processes".
  • The model key path is the name of the column.

Note the following referencing binding on the array controller class:


6. Connect the table's delegate to our Process Controller object:


7. Create content array bindings on the Array Of Running Processes class:

@LauraAubin LauraAubin force-pushed the process-list-app-controller branch from cd7a178 to 7d1bae4 Compare March 21, 2018 03:04
@LauraAubin LauraAubin force-pushed the process-list-app-controller branch from c0065ba to 3eb33af Compare March 21, 2018 03:05
#import <Cocoa/Cocoa.h>

@interface ProcessController : NSObject
@property (weak, readonly) NSWorkspace *workspace;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weak:

Keeps a pointer to the object so long as it exists. When it is deallocated, pointer is set to nil automatically.


Readonly

Only generate a getter, no setter. Will warn you if you try to change this property.


NSWorkspace

Can launch apps and handle file services. There is one shared workspace within the entire app.


@interface ProcessController : NSObject
@property (weak, readonly) NSWorkspace *workspace;
@property(weak, readonly) NSArray *sortDescriptors;
Copy link
Owner Author

@LauraAubin LauraAubin Mar 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorts an array as part of arrangeObjects.


@implementation ProcessController

- (void)applicationDidBecomeActive:(NSNotification *)notification
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


- (void)applicationDidBecomeActive:(NSNotification *)notification
{
[self.arrayOfRunningProcesses rearrangeObjects];
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rearrangeObjects is a method that calls arrangeObjects which returns an array containing filtered and sorted (sortDescriptors) objects.

NSLog(@"Array: %@", _arrayOfRunningProcesses);
}

- (NSWorkspace *)workspace;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workspaces are used to launch apps and perform file services.


- (NSWorkspace *)workspace;
{
return [NSWorkspace sharedWorkspace];
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can call sharedWorkspace from anywhere in the app, so it is needed to bind to the UI.

@LauraAubin LauraAubin merged commit b927116 into master Mar 24, 2018
@LauraAubin LauraAubin deleted the process-list-app-controller branch March 24, 2018 01:15
@LauraAubin LauraAubin changed the title Visualize currently running applications Visualize currently running applications by name Mar 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant