1 #include "AutoRaiseApp.h" 2 #include "AutoRaiseIcon.h" 3 4 AutoRaiseApp::AutoRaiseApp() 5 : BApplication( APP_SIG ) 6 { 7 removeFromDeskbar(NULL); 8 fPersist = true; 9 fDone = false; 10 11 //since the tray item shows an icon, and the class TrayView needs to be 12 //able to know the location of the executing binary, we write into the 13 //settings file this critical information when the app is fired up 14 app_info info; 15 be_app->GetAppInfo(&info); 16 17 //now, put the path into the settings file 18 AutoRaiseSettings settings; 19 settings.SetAppPath(info.ref); 20 } 21 22 AutoRaiseApp::~AutoRaiseApp() 23 { 24 return; 25 } 26 27 void AutoRaiseApp::ArgvReceived(int32 argc, char ** argv) 28 { 29 BString option; 30 31 for (int32 i = 1; i < argc; i++) 32 { 33 option = argv[i]; 34 if (option.IFindFirst("deskbar") != B_ERROR) 35 fPersist = false; 36 37 if (option.IFindFirst("persist") != B_ERROR) 38 fPersist = true; 39 40 if (option.IFindFirst("-h") != B_ERROR 41 || option.IFindFirst("help") != B_ERROR) { 42 BString usageNote = 43 "\nUsage: " APP_NAME " [options]\n\t--deskbar\twill not open " 44 "window, will just put " APP_NAME " into tray\n\t--persist (default) will put " 45 APP_NAME " into tray such that it remains across reboots\n"; 46 printf(usageNote); 47 fDone = true; 48 be_app_messenger.SendMessage(B_QUIT_REQUESTED); 49 } 50 } 51 } 52 53 void AutoRaiseApp::ReadyToRun() 54 { 55 if (!fDone) 56 PutInTray(fPersist); 57 be_app_messenger.SendMessage(B_QUIT_REQUESTED); 58 } 59 60 void AutoRaiseApp::PutInTray(bool persist) 61 { 62 BDeskbar db; 63 64 if (!persist) 65 db.AddItem(new TrayView); 66 else { 67 BRoster roster; 68 entry_ref ref; 69 roster.FindApp(APP_SIG, &ref); 70 int32 id; 71 db.AddItem(&ref, &id); 72 } 73 } 74 75 int main() 76 { 77 AutoRaiseApp *app = new AutoRaiseApp(); 78 app->Run(); 79 } 80