コード例 #1
0
ファイル: AppDelegate.cs プロジェクト: daviddw/oss-public
        public override void AwakeFromNib()
        {
            // initialise resigned state
            iSessionResigned = false;

            // load some images from the bundle
            NSImage largeIcon = new NSImage(NSBundle.MainBundle.PathForImageResource("IconLarge.png"));

            // create the app helper
            iHelper = new Helper(Environment.GetCommandLineArgs());
            iHelper.ProcessOptionsFileAndCommandLine();

            // add a crash log dumper
            CrashLogDumperWindowController d = new CrashLogDumperWindowController(largeIcon, iHelper.Title, iHelper.Product, iHelper.Version);

            d.LoadWindow();
            iHelper.AddCrashLogDumper(d);

            // create auto update view and helper
            iHelperAutoUpdate = new HelperAutoUpdate(iHelper, new Linn.Toolkit.Mac.ViewAutoUpdateStandard(largeIcon), new Invoker(), (s, e) => {});
            iHelperAutoUpdate.Start();

            // create the main songcast model
            iModel = new Model(new Invoker(), iHelper);
            iModel.EventEnabledChanged += ModelEnabledChanged;

            // create the preferences 'view' for communicating with the system preferences app
            iViewPreferences = new ViewPreferences(new Invoker(), iModel, iHelperAutoUpdate);

            // creating the status item with a length of -2 is equivalent to the call
            // [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength]
            iStatusItem = NSStatusBar.SystemStatusBar.CreateStatusItem(-2);
            iStatusItem.HighlightMode = false;
            iStatusItem.Target        = this;
            iStatusItem.Action        = new Selector("statusItemClicked:");

            // setup system event notifications
            NSNotificationCenter center = NSWorkspace.SharedWorkspace.NotificationCenter;

            center.AddObserver(this, new Selector("willSleep:"), new NSString("NSWorkspaceWillSleepNotification"), null);
            center.AddObserver(this, new Selector("didWake:"), new NSString("NSWorkspaceDidWakeNotification"), null);
            center.AddObserver(this, new Selector("sessionDidResignActive:"), new NSString("NSWorkspaceSessionDidResignActiveNotification"), null);
            center.AddObserver(this, new Selector("sessionDidBecomeActive:"), new NSString("NSWorkspaceSessionDidBecomeActiveNotification"), null);

            // create the main window
            iMainWindow = new MainWindowController();
            iMainWindow.LoadWindow();
            iMainWindow.Window.DidResignKey      += MainWindowDidResignKey;
            iMainWindow.Window.CollectionBehavior = NSWindowCollectionBehavior.CanJoinAllSpaces;

            // create the xapp controller and view
            iXappController = new XappController(iModel, new Invoker());
            iXappController.MainPage.EventShowConfig += ShowConfig;
            iXappController.MainPage.EventShowHelp   += ShowHelp;
            iViewer = new ViewerBrowser(iMainWindow.WebView, iXappController.MainPageUri);
        }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: daviddw/oss-public
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            try
            {
                // create helpers
                iHelper = new Helper(e.Args);
                ICrashLogDumper d = new CrashLogDumperWindow(ResourceManager.Icon, iHelper.Title, iHelper.Product, iHelper.Version);
                iHelper.AddCrashLogDumper(d);

                iHelperAutoUpdate = new HelperAutoUpdate(iHelper, new Linn.Toolkit.Wpf.ViewAutoUpdateStandard(ResourceManager.IconSongcaster, Linn.Songcast.Properties.Resources.IconLarge), new Invoker(this.Dispatcher));
                iHelperAutoUpdate.Start();

                // create the model
                iModel = new Model(new Invoker(this.Dispatcher), iHelper);

                iHelper.ProcessOptionsFileAndCommandLine();

                // this should be created before PreferencesWindowClosing event can be called or PreferencesWindowClosing will raise a null reference exception
                iWaitMainWindowClosed = new AutoResetEvent(false);

                // create the preferences window and controller
                iPreferencesWindow          = new PreferencesWindow(iHelper, new PreferenceBindings(iModel, iHelperAutoUpdate.OptionPageUpdates), iModel, iHelperAutoUpdate);
                iPreferencesWindow.Closing += PreferencesWindowClosing;
                iPreferencesWindow.EventButtonHelpClicked += OpenHelp;

                // create the main window
                iMainWindow              = new MainWindow();
                iMainWindow.Deactivated += MainWindowDeactivated;

                // create the xapp controller and view
                iXappController = new XappController(iModel, new Invoker(this.Dispatcher));
                iXappController.MainPage.EventShowConfig += OpenPreferences;
                iXappController.MainPage.EventShowHelp   += OpenHelp;
                iViewer = new ViewerBrowser(iMainWindow.WebBrowser, iXappController.MainPageUri);

                // create the sys tray icon
                iFormSysTray = new FormSysTray(iModel);
                iFormSysTray.EventIconClick += SysTrayIconClick;

                // start the model
                System.Drawing.Image   image  = System.Drawing.Image.FromStream(ResourceManager.Icon.StreamSource);
                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                iModel.Start("linn.co.uk", "Linn", "http://www.linn.co.uk", "http://www.linn.co.uk", stream.ToArray(), "image/png");

                bool createdNew;
                iWaitHandleMainWindow = new EventWaitHandle(false, EventResetMode.ManualReset, "LinnSongcastOpenPreferences", out createdNew);
                if (!createdNew)
                {
                    iWaitHandleMainWindow.Set();
                    //MessageBox.Show("Linn Songcast is already running", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    App.Current.Shutdown(0);
                    return;
                }

                iWaitHandleExit = new EventWaitHandle(false, EventResetMode.ManualReset, "LinnSongcastExit", out createdNew);
                Assert.Check(createdNew);

                iThreadMainWindow = new Thread(ProcessOpenMainWindow);
                iThreadMainWindow.IsBackground = true;
                iThreadMainWindow.Start();

                iThreadExit = new Thread(ProcessExit);
                iThreadExit.IsBackground = true;
                iThreadExit.Start();

                Microsoft.Win32.SystemEvents.PowerModeChanged += PowerModeChanged;
            }
            catch (SongcastError)
            {
                MessageBox.Show("Failed to initialise Linn Songcast Driver", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                App.Current.Shutdown(1);
            }
        }