Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/ti.UI/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ elif build.is_win32():

elif build.is_osx():
env.Append(FRAMEWORKPATH=[build.tp('growl')])
env.Append(FRAMEWORKS=['Cocoa','Carbon', 'IOKit', 'Growl'])
env.Append(FRAMEWORKS=['Cocoa','Carbon', 'IOKit', 'Growl', 'DiskArbitration'])
sources = sources + Glob('mac/*.mm') + Glob('mac/*.cpp')
env.Append(CCFLAGS=['-x', 'objective-c++'])

Expand Down
1 change: 1 addition & 0 deletions modules/ti.UI/mac/UIMac.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class UIMac : public UI {
NSObject* application;
AutoPtr<MenuMac> activeMenu;
AutoPtr<UserWindowMac> activeWindow;
DASessionRef session;

void InstallMenu (MenuItemMac*);
};
Expand Down
75 changes: 75 additions & 0 deletions modules/ti.UI/mac/UIMac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,71 @@
#include "TrayItemMac.h"
#include "UserWindowMac.h"

#include <stdio.h>
#include <DiskArbitration/DiskArbitration.h>

#define DBG if(0)
void printPair(const void* key, const void* value, void* context)
{
printf("{\n");
CFShow(key);
CFShow(value);
printf("}\n");
}
inline bool TestBool(const void *v)
{
return v && CFBooleanGetValue((CFBooleanRef)v);
}
inline bool TestStr(const void *v, CFStringRef s)
{
return v && !CFStringCompare((CFStringRef)v, s, 0);
}

void report_disk(DADiskRef disk, void *context, const char *event, CFDictionaryRef desc = NULL)
{
if (!desc)
desc = DADiskCopyDescription(disk);
if (desc) {
DBG CFDictionaryApplyFunction(desc, printPair, context);
DBG printf("disk %s %s\n", DADiskGetBSDName(disk), event);
if (TestBool(CFDictionaryGetValue(desc, kDADiskDescriptionMediaLeafKey))) {
DBG DBG printf("disk %s is leafy\n", DADiskGetBSDName(disk));
if (TestBool(CFDictionaryGetValue(desc, kDADiskDescriptionMediaRemovableKey))) {
DBG printf("disk %s is removable\n", DADiskGetBSDName(disk));
if (TestBool(CFDictionaryGetValue(desc, kDADiskDescriptionMediaWritableKey))) {
DBG printf("disk %s is writable\n", DADiskGetBSDName(disk));
if (!TestBool(CFDictionaryGetValue(desc, kDADiskDescriptionVolumeNetworkKey))) {
DBG printf("disk %s is not networked\n", DADiskGetBSDName(disk));
if (TestStr(CFDictionaryGetValue(desc, kDADiskDescriptionMediaKindKey), CFSTR("IOMedia"))) {
DBG printf("disk %s is not optical\n", DADiskGetBSDName(disk));
DBG printf("disk %s %s\n", DADiskGetBSDName(disk), event);
GlobalObject::GetInstance()->FireEvent(event);
}
}
}
}
}
CFRelease(desc);
}
}

void hello_disk(DADiskRef disk, void *context)
{
report_disk(disk, context, "volume.added");
}

void goodbye_disk(DADiskRef disk, void *context)
{
report_disk(disk, context, "volume.removed");
}

void follow_disk(DADiskRef disk, CFArrayRef keys, void *context)
{
CFDictionaryRef desc = DADiskCopyDescription(disk);
if (desc && CFDictionaryGetValue(desc, kDADiskDescriptionVolumePathKey))
report_disk(disk, context, "volume.added", desc);
}

@interface NSApplication (LegacyWarningSurpression)
- (id) dockTile;
@end
Expand Down Expand Up @@ -79,12 +144,22 @@ - (id)owner;
// make sure this is part of the upcoming security work
[WebView registerURLSchemeAsLocal:@"app"];
[WebView registerURLSchemeAsLocal:@"ti"];

session = DASessionCreate(kCFAllocatorDefault);

DBG DARegisterDiskAppearedCallback(session, NULL, hello_disk, NULL);
DARegisterDiskDisappearedCallback(session, NULL, goodbye_disk, NULL);
DARegisterDiskDescriptionChangedCallback(session, NULL, kDADiskDescriptionWatchVolumePath, follow_disk, NULL);

DASessionScheduleWithRunLoop(session,
CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
}

UIMac::~UIMac()
{
[application release];
[savedDockView release];
CFRelease(session);
}

AutoPtr<Menu> UIMac::CreateMenu()
Expand Down