Example #1
0
            public void HandleAppleEvent(NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt)
            {
                var url = evt.ParamDescriptorForKeyword(DirectObject).StringValue;
                var uri = new Uri(url);

                OpenUrl(WebUtils.GetNativeUrl(uri));
            }
Example #2
0
        public NSAppleEventDescriptor ExecuteAppleEvent(NSAppleEventDescriptor @event, out NSDictionary errorInfo)
        {
            NSAppleEventDescriptor result;
            IntPtr errorInfoHandle = Marshal.AllocHGlobal(4);

            if (IsDirectBinding)
            {
                result = (NSAppleEventDescriptor)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr(base.Handle, Selector.GetHandle("executeAppleEvent:error:"), @event.Handle, errorInfoHandle));
            }
            else
            {
                result = (NSAppleEventDescriptor)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSendSuper_IntPtr_IntPtr(base.SuperHandle, Selector.GetHandle("executeAppleEvent:error:"), @event.Handle, errorInfoHandle));
            }
            if (result == null)
            {
                IntPtr errorInfoHandle2 = Marshal.ReadIntPtr(errorInfoHandle);
                errorInfo = (NSDictionary)Runtime.GetNSObject(errorInfoHandle2);
            }
            else
            {
                errorInfo = null;
            }
            Marshal.FreeHGlobal(errorInfoHandle);
            return(result);
        }
Example #3
0
        void GetUrlWithReplyEvent(NSAppleEventDescriptor @event, NSAppleEventDescriptor replyEvent)
        {
            // from /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/Headers/AppleEvents.h
            const uint keyDirectObject = 757935405;  // '----'
            const uint keyErrorNumber  = 1701999214; // 'errn'
            const uint keyErrorString  = 1701999219; // 'errs'

            string errorMessage = null;

            var urlString = @event?.ParamDescriptorForKeyword(keyDirectObject).StringValue;

            if (urlString != null)
            {
                SessionDocumentController
                .SharedDocumentController
                .OpenDocument(new NSUrl(urlString));

                applicationShouldOpenUntitledFile = false;
            }

            replyEvent.SetParamDescriptorforKeyword(
                NSAppleEventDescriptor.DescriptorWithInt32(errorMessage == null ? 0 : 1),
                keyErrorNumber);

            if (errorMessage != null)
            {
                replyEvent.SetParamDescriptorforKeyword(
                    NSAppleEventDescriptor.DescriptorWithString(errorMessage),
                    keyErrorString);
            }
        }
Example #4
0
        private void HandleOpenURL(NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvent)
        {
            Log.Information("Handling Open URL Event");
            for (int i = 1; i <= evt.NumberOfItems; i++)
            {
                var innerDesc = evt.DescriptorAtIndex(i);

                //Grab the URL
                if (!string.IsNullOrEmpty(innerDesc.StringValue))
                {
                    //Get a hold of the Main Application View Model
                    Log.Information($"Got URL:{innerDesc.StringValue}");
                    this.mainWindow = AvaloniaLocator.Current.GetService <MainWindow>();
                    var mwvm = (MainWindowViewModel)this.mainWindow.DataContext;

                    //Get a hold of the currently loaded Model (main menu)
                    if (mwvm.Content.GetType() == typeof(MainMenuViewModel))
                    {
                        var mmvm = mwvm.Content as MainMenuViewModel;
                        //If there is a Loaded Identity then Invoke the Authentication Dialog
                        if (mmvm.CurrentIdentity != null)
                        {
                            Log.Information($"Open URL Data: {innerDesc.StringValue}");
                            mmvm.AuthVM       = new AuthenticationViewModel(new Uri(innerDesc.StringValue));
                            mwvm.PriorContent = mwvm.Content;
                            mwvm.Content      = mmvm.AuthVM;
                            Dispatcher.UIThread.Post(() =>
                            {
                                (Application.Current as App).RestoreMainWindow();
                            });
                        }
                    }
                }
            }
        }
Example #5
0
        public override void ViewDidMoveToWindow()
        {
            base.ViewDidMoveToWindow();

            TrackName.StringValue  = currentDelegate.controller.Track;
            ArtistName.StringValue = currentDelegate.controller.Artist;

            if (currentDelegate.controller.App == "iTunes")
            {
                PlayerIcon.Image = new NSImage("icon_itunes.pdf");
                script           = new NSAppleScript(File.ReadAllText("Scripts/GetAlbumArtiTunes.txt"));
                result           = script.ExecuteAndReturnError(out errors);
                NSImage cover = new NSImage(result.Data);
                AlbumArtView.Image  = cover;
                ThumbnailView.Image = cover;
            }
            else
            {
                PlayerIcon.Image = new NSImage("icon_spotify.pdf");
                script           = new NSAppleScript(File.ReadAllText("Scripts/GetAlbumArtSpotify.txt"));
                result           = script.ExecuteAndReturnError(out errors);
                NSUrl   artworkurl = new NSUrl(result.StringValue);
                NSImage cover      = new NSImage(artworkurl);
                AlbumArtView.Image  = cover;
                ThumbnailView.Image = cover;
            }
        }
Example #6
0
        //itunesへApplescriptでリクエストを送信して結果を返す関数
        private NSAppleEventDescriptor Requesttoitunes(String _script)
        {
            NSAppleScript          appleScript = new NSAppleScript(_script);
            NSDictionary           error;
            NSAppleEventDescriptor result = appleScript.ExecuteAndReturnError(out error);

            return(result);
        }
Example #7
0
 public void GetUrl(NSAppleEventDescriptor evt, NSAppleEventDescriptor withReplyEvent)
 {
     passedUrl = evt.ParamDescriptorForKeyword(FourCC("----")).StringValue;
     if (isLoaded)
     {
         invoke.Invoke(LoadPassedUrl);
     }
 }
Example #8
0
        public void MonoApplication_HandleURLEvent(NSAppleEventDescriptor value, NSAppleEventDescriptor reply)
        {
            var url = value.ParamDescriptorForKeyword(AEKeyword.DirectObject)?.StringValue;

            if (url != null)
            {
                TryOpen(new string[] { url }, Msg.WM_OPEN_URLS);
            }
        }
Example #9
0
 public static bool UrlHandleEvent(NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt)
 {
     foreach (var item in callBacks)
     {
         var s = item.Value(evt, replyEvt);
         if (s)
         {
             return(true);
         }
     }
     return(false);
 }
Example #10
0
        //現在再生中のトラック名取得関数
        public String GetTrackName()
        {
            String script = string.Format("tell application \"{0}\" to get name of current track", this.name);
            NSAppleEventDescriptor result = Requesttoitunes(script);

            if (result == null)
            {
                return("Null");
            }

            return(result.StringValue);
        }
Example #11
0
        public void HandleGetURLEvent(NSAppleEventDescriptor appleEvent,
        	NSAppleEventDescriptor reply)
        {
            // Received event is a list (1-based) of URL strings
            for (int i = 1; i <= appleEvent.NumberOfItems; i++) {
                NSAppleEventDescriptor innerDesc = appleEvent.DescriptorAtIndex (i);

                string url = innerDesc.StringValue;

                if( url != null ) {
                    Program.Controller.FetchInviteFromURL( url );
                }
            }
        }
Example #12
0
        void GetCurrentSelectedSolutionPath(NSAppleEventDescriptor @event, NSAppleEventDescriptor reply)
        {
            LoggingService.LogInfo($"{nameof (GetCurrentSelectedSolutionPath)}: received AppleEvent {@event}");

            var solutionPath = IdeApp.Workspace.CurrentSelectedSolution?.FileName.FullPath.ToString();

            if (!string.IsNullOrEmpty(solutionPath))
            {
                reply.SetParamDescriptorforKeyword(
                    NSAppleEventDescriptor.DescriptorWithString(solutionPath),
                    keyDirectObject);

                LoggingService.LogInfo($"{nameof (GetCurrentSelectedSolutionPath)}: replying to AppleEvent {@event} with {solutionPath}");
            }
        }
Example #13
0
        public MusicPlayer(String _name)
        {
            this.name = _name;

            //プレイリストの取得
            String script = string.Format("tell application \"{0}\" to get name of user playlists", this.name);
            NSAppleEventDescriptor result = Requesttoitunes(script);

            nint B = result.NumberOfItems;

            playlist = new String[B];
            for (int i = 0; i < playlist.Length; i++)
            {
                playlist[i] = result.DescriptorAtIndex(i + 1).StringValue;
            }
        }
Example #14
0
        public void AppleScript_BasicTest()
        {
#pragma warning disable 0219
            const string  script = @"tell application ""Finder""
end tell";
            NSAppleScript s      = new NSAppleScript(script);

            NSDictionary errorInfo;
            bool         success = s.CompileAndReturnError(out errorInfo);
            Assert.IsTrue(success);
            Assert.IsNull(errorInfo);
            Assert.IsTrue(s.Compiled);

            NSAppleEventDescriptor descriptor = s.ExecuteAndReturnError(out errorInfo);
            Assert.IsNull(errorInfo);
#pragma warning restore 0219
        }
Example #15
0
        private void HandleGetURLEvent(NSAppleEventDescriptor descriptor, NSAppleEventDescriptor replyEvent)
        {
            // Breakpoint here, debug normally and *then* call your URL
            try
            {
                var keyDirectObject = "----";
                var keyword         = (((uint)keyDirectObject[0]) << 24 |
                               ((uint)keyDirectObject[1]) << 16 |
                               ((uint)keyDirectObject[2]) << 8 |
                               ((uint)keyDirectObject[3]));

                var openinArgs = descriptor.ParamDescriptorForKeyword(keyword).StringValue;
                ParseOpeningString(openinArgs);
            }
            catch
            {
            }
        }
Example #16
0
        private void HandleGetURLEvent(NSAppleEventDescriptor descriptor, NSAppleEventDescriptor replyEvent)
        {
            // stackoverflow.com/questions/1945
            // https://forums.xamarin.com/discussion/9774/custom-url-schema-handling
            var keyDirectObject = "----";
            var keyword         =
                (((uint)keyDirectObject[0]) << 24 |
                    ((uint)keyDirectObject[1]) << 16 |
                    ((uint)keyDirectObject[2]) << 8 |
                    ((uint)keyDirectObject[3]));

            var urlString = descriptor.ParamDescriptorForKeyword(keyword).StringValue;

            using (var alert = new NSAlert()){
                alert.MessageText = urlString;
                alert.RunSheetModal(null);
            }
        }
Example #17
0
        static void Main(string[] args)
        {
            NSApplication.Init();
            Logging.Log("iMessage Bridge 1.0");
            NSUserDefaults.StandardUserDefaults.RegisterDefaults(NSDictionary.FromFile(NSBundle.MainBundle.PathForResource("DefaultPreferences", "plist")));

            // Find out if user is logged into iMessage.
            NSAppleScript          asConnectionStatus = new NSAppleScript("tell application \"Messages\" to get 1st service's connection status whose service type = iMessage");
            NSDictionary           ei;
            NSAppleEventDescriptor aed = asConnectionStatus.ExecuteAndReturnError(out ei);

            if (ei == null)
            {
                if (aed.StringValue == "dcon") // iMessage service is disconnected.
                {
                    NSAlert alert = new NSAlert()
                    {
                        MessageText     = "It appears you're not signed in to iMessage.",
                        InformativeText = "The bridge will not work if you are not signed in. Would you like to sign in to iMessage?"
                    };
                    alert.AddButton("Yes");
                    alert.AddButton("Not now");
                    NSRunningApplication.CurrentApplication.Activate(NSApplicationActivationOptions.ActivateIgnoringOtherWindows);
                    if (alert.RunModal() == 1000) // User clicks yes.
                    {
                        Process.Start("/Applications/Messages.app");
                    }
                    Environment.Exit(1);
                }
            }
            DatabaseStore.Init();
            HttpServer.Start();
            StreamServer.Start();
            if (NSUserDefaults.StandardUserDefaults.BoolForKey("DiscoveryMode"))
            {
                Discovery.Register();
            }

            NSApplication app = NSApplication.SharedApplication;

            app.Delegate = new AppDelegate();
            app.Run();
        }
Example #18
0
        public void HandleGetURLEvent(NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt)
        {
            NSError error;

            shouldOpenInitialFile = evt.NumberOfItems == 0;

            // Received event is a list (1-based) of URL strings
            for (int i = 1; i <= evt.NumberOfItems; i++)
            {
                var innerDesc = evt.DescriptorAtIndex(i);
                // The next call works fine but is Lion-specific
                // controller.OpenDocument (new NSUrl (innerDesc.StringValue), i == evt.NumberOfItems, delegate {});
                if (!string.IsNullOrEmpty(innerDesc.StringValue))
                {
                    NSUrl url = new NSUrl(innerDesc.StringValue);
                    Call_OpenDocument(url, true, out error);
                }
            }
        }
Example #19
0
        void HandleGetUrlEvent(NSAppleEventDescriptor descriptor, NSAppleEventDescriptor reply)
        {
            var openUrlEvent = OpenUrl;

            if (openUrlEvent == null)
            {
                return;
            }

            string keyDirectObjectString = "----";
            uint   keywordDirectObject   = (((uint)keyDirectObjectString [0]) << 24 |
                                        ((uint)keyDirectObjectString [1]) << 16 |
                                        ((uint)keyDirectObjectString [2]) << 8 |
                                        ((uint)keyDirectObjectString [3]));

            string urlString = descriptor.ParamDescriptorForKeyword(keywordDirectObject).ToString();

            openUrlEvent(NSApplication.SharedApplication, new OpenUrlEventArgs(urlString));
        }
Example #20
0
        partial void SettingsButtonClick(NSObject sender) 

        {
            
 var current = NSApplication.SharedApplication.CurrentEvent; 

            //Checking if the app is in the login items or not
            var                    script      = "tell application \"System Events\"\n get the name of every login item\n if login item \"Ambar\" exists then\n return true\n else\n return false\n end if\n end tell";
            NSAppleScript          appleScript = new NSAppleScript(script);
            var                    errors      = new NSDictionary();
            NSAppleEventDescriptor result      = appleScript.ExecuteAndReturnError(out errors);

            isLoginItem = result.BooleanValue;

            if (!isLoginItem)
            {
                launch.State = NSCellStateValue.Off;
            }
            else if (isLoginItem)
            {
                launch.State = NSCellStateValue.On;
            }
            
 NSMenu.PopUpContextMenu(settingsMenu, current, sender as NSView); 

        }
Example #21
0
        public override void ViewDidMoveToWindow()
        {
            base.ViewDidMoveToWindow();

            LyricsTextView.Value   = currentDelegate.controller.TrackLyrics.message.body.lyrics.lyrics_body;
            TrackName.StringValue  = currentDelegate.controller.Track;
            ArtistName.StringValue = currentDelegate.controller.Artist;

            if (currentDelegate.controller.TrackLyrics.message.body.lyrics.@explicit == 1)
            {
                ExplicitTag.Hidden = false;
            }
            else
            {
                ExplicitTag.Hidden = true;
            }

            if (currentDelegate.controller.App == "iTunes")
            {
                PlayerIcon.Image = new NSImage("icon_itunes.pdf");
                script           = new NSAppleScript(File.ReadAllText("Scripts/GetAlbumArtiTunes.txt"));
                result           = script.ExecuteAndReturnError(out errors);
                NSImage cover = new NSImage(result.Data);
                AlbumArtView.Image  = cover;
                ThumbnailView.Image = cover;
            }
            else
            {
                PlayerIcon.Image = new NSImage("icon_spotify.pdf");
                script           = new NSAppleScript(File.ReadAllText("Scripts/GetAlbumArtSpotify.txt"));
                result           = script.ExecuteAndReturnError(out errors);
                NSUrl   artworkurl = new NSUrl(result.StringValue);
                NSImage cover      = new NSImage(artworkurl);
                AlbumArtView.Image  = cover;
                ThumbnailView.Image = cover;
            }

            containerHeight = (float)LyricsTextView.Bounds.Height;
        }
Example #22
0
        private void FetchLyrics()
        {
            stateMachine.StartLoading();

            if (Reachability.IsNetworkAvailable())
            {
                script = new NSAppleScript(File.ReadAllText("Scripts/GetCurrentSong.txt"));
                result = script.ExecuteAndReturnError(out errors);

                //The NumberofItems property is being used to handle different use cases. Check GetCurrentSong.txt in Scripts folder to know more
                if (result.NumberOfItems == 3)
                {
                    artist = result.DescriptorAtIndex(1).StringValue;
                    track  = result.DescriptorAtIndex(2).StringValue;
                    app    = result.DescriptorAtIndex(3).StringValue;

                    var lyrics = lyricsHelper.GetLyrics(track, artist, (response, artist_name, share_url) =>
                    {
                        tracklyrics = JsonConvert.DeserializeObject <TrackLyrics.RootObject>(response);

                        if (tracklyrics.message.body.lyrics.instrumental == 0)
                        {
                            track_share_url = share_url;
                            stateMachine.ShowContent();
                        }
                        else
                        {
                            stateMachine.ShowEmpty();
                        }
                    });
                }
                else if (result.NumberOfItems == 0)
                {
                    switch (result.StringValue)
                    {
                    //Transitioning to error state of state machine and calling the corresponding delegate method
                    //These delegates method are being used so that one view can be reused for various error cases.
                    case "1":
                        stateMachine.ShowError();
                        NothingPlayingFound?.Invoke(this, null);
                        break;

                    case "2":
                        stateMachine.ShowError();
                        NoMusicAppRunningFound?.Invoke(this, null);
                        break;

                    case "3":
                        stateMachine.ShowError();
                        MultiPlayingFound?.Invoke(this, null);
                        break;
                    }
                }
                else
                {
                    stateMachine.ShowError();
                    LyricsNotFoundOccurred?.Invoke(this, null);
                }
            }

            else
            {
                stateMachine.ShowError();
                NetworkErrorOccurred?.Invoke(this, null);
            }
        }
Example #23
0
 public void UrlHandleEvent(NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt)
 {
     Native.UrlHandleEvent(evt, replyEvt);
 }
Example #24
0
        internal virtual void HandleGetURLEvent(NSAppleEventDescriptor ae, NSAppleEventDescriptor aeReply)
        {
            string url = ae.ParamDescriptorForKeyword(AEKeyword.DirectObject).StringValue;

            TryOpenFiles(new string[] { url }, Msg.WM_OPEN_URLS);
        }
Example #25
0
 //前の曲に移動
 public void NextTrack()
 {
     String script = string.Format("tell application \"{0}\" to next track", this.name);
     NSAppleEventDescriptor result = Requesttoitunes(script);
 }
Example #26
0
 public virtual bool OpenUrls(NSUrl[] urls, string bundleIdentifier, NSWorkspaceLaunchOptions options, NSAppleEventDescriptor descriptor)
 {
     return(_OpenUrls(urls, bundleIdentifier, options, descriptor, null));
 }
Example #27
0
 public virtual bool OpenUrls(NSUrl[] urls, string bundleIdentifier, NSWorkspaceLaunchOptions options, NSAppleEventDescriptor descriptor, string[] identifiers)
 {
     // Ignore the passed in argument, because if you pass it in we will crash on cleanup.
     return(_OpenUrls(urls, bundleIdentifier, options, descriptor, null));
 }
Example #28
0
		public void HandleGetURLEvent (NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt)
		{
			NSError error;
			shouldOpenInitialFile = evt.NumberOfItems == 0;
			
			// Received event is a list (1-based) of URL strings
			for (int i = 1; i <= evt.NumberOfItems; i++) {
				var innerDesc = evt.DescriptorAtIndex (i);
				// The next call works fine but is Lion-specific 
				//controller.OpenDocument (new NSUrl (innerDesc.StringValue), i == evt.NumberOfItems, delegate {});
				Call_OpenDocument (new NSUrl (innerDesc.StringValue), i == evt.NumberOfItems, out error);
			}
		}
Example #29
0
		public void UrlHandleEvent (NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt)
		{
			var url = evt.ParamDescriptorForKeyword (AppleEventParameters.DirectObject).StringValue;
			SimpleAuth.NativeSafariAuthenticator.ResumeAuth (url);
		}
Example #30
0
 //現在の曲を再生、停止する関数
 public void PlayPause()
 {
     String script = string.Format("tell application \"{0}\" to playpause", this.name);
     NSAppleEventDescriptor result = Requesttoitunes(script);
 }
Example #31
0
		void HandleGetUrlEvent(NSAppleEventDescriptor descriptor, NSAppleEventDescriptor reply)
		{
			var openUrlEvent = OpenUrl;
			if (openUrlEvent == null)
				return;
			
			string keyDirectObjectString = "----";
			uint keywordDirectObject = (((uint)keyDirectObjectString [0]) << 24 |
				((uint)keyDirectObjectString [1]) << 16 |
				((uint)keyDirectObjectString [2]) << 8 |
				((uint)keyDirectObjectString [3]));
			
			string urlString = descriptor.ParamDescriptorForKeyword (keywordDirectObject).ToString ();
			openUrlEvent (NSApplication.SharedApplication, new OpenUrlEventArgs (urlString));
		}
Example #32
0
 //指定されたプレイリストを再生する関数
 public void Playplaylist(String _player_name, String _music_title)
 {
     String script = "tell application \"" + _player_name + "\" to play playlist \"" + _music_title + "\"";
     NSAppleEventDescriptor result = Requesttoitunes(script);
 }
Example #33
0
        public void UrlHandleEvent(NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt)
        {
            var url = evt.ParamDescriptorForKeyword(AppleEventParameters.DirectObject).StringValue;

            SimpleAuth.NativeSafariAuthenticator.ResumeAuth(url);
        }