コード例 #1
0
        private async Task <StorageFile?> NativePickerPickSaveFileAsync(CancellationToken token)
        {
            var showAllEntryParameter = "true";
            var fileTypeMapParameter  = JsonHelper.Serialize(BuildFileTypesMap());

            var suggestedFileName = SuggestedFileName != "" ? WebAssemblyRuntime.EscapeJs(SuggestedFileName) : "";

            var id = WebAssemblyRuntime.EscapeJs(SettingsIdentifier);

            var startIn = SuggestedStartLocation.ToStartInDirectory();
            var promise = $"{JsType}.nativePickSaveFileAsync({showAllEntryParameter},'{WebAssemblyRuntime.EscapeJs(fileTypeMapParameter)}','{suggestedFileName}','{id}','{startIn}')";
            var nativeStorageItemInfo = await WebAssemblyRuntime.InvokeAsync(promise);

            if (nativeStorageItemInfo is null)
            {
                return(null);
            }

            var info = JsonHelper.Deserialize <NativeStorageItemInfo>(nativeStorageItemInfo);

            return(StorageFile.GetFromNativeInfo(info));
        }
コード例 #2
0
ファイル: UIElement.wasm.cs プロジェクト: Level0r0s/Uno
        private void ReleasePointerCaptureNative(Pointer pointer)
        {
            var command = "Uno.UI.WindowManager.current.releasePointerCapture(\"" + HtmlId + "\", " + pointer.PointerId + ");";

            WebAssemblyRuntime.InvokeJS(command);
        }
コード例 #3
0
ファイル: Clipboard.wasm.cs プロジェクト: unoplatform/uno
        private static void StopContentChanged()
        {
            var command = $"{JsType}.stopContentChanged()";

            WebAssemblyRuntime.InvokeJS(command);
        }
コード例 #4
0
        partial void DeactivateScreenLock()
        {
            var command = $"{JsType}.deactivateScreenLock()";

            WebAssemblyRuntime.InvokeJS(command);
        }
コード例 #5
0
 private static bool TryReadJsFloat(string property, out float value) =>
 float.TryParse(WebAssemblyRuntime.InvokeJS(property), out value);
コード例 #6
0
 protected override void DisableFrameReporting() => WebAssemblyRuntime.InvokeJSWithInterop($"{this}.DisableFrameReporting();");
コード例 #7
0
 protected override void SetAnimationFramesInterval() => WebAssemblyRuntime.InvokeJSWithInterop($"{this}.SetAnimationFramesInterval();");
コード例 #8
0
ファイル: StorageFolder.native.wasm.cs プロジェクト: kcmd/uno
            internal async Task DeleteItemAsync(string itemName)
            {
                var result = await WebAssemblyRuntime.InvokeAsync($"{JsType}.deleteItemAsync(\"{_id}\", \"{WebAssemblyRuntime.EscapeJs(itemName)}\")");

                if (result == null)
                {
                    throw new UnauthorizedAccessException($"Could not delete item {itemName}");
                }
            }
コード例 #9
0
        partial void DisposeNative()
        {
            var removeInstanceCommand = $"{JsType}.removePort('{_managedId}')";

            WebAssemblyRuntime.InvokeJS(removeInstanceCommand);
        }
コード例 #10
0
ファイル: StorageFolder.native.wasm.cs プロジェクト: kcmd/uno
            public override async Task <StorageFile> GetFileAsync(string name, CancellationToken token)
            {
                var fileInfoJson = await WebAssemblyRuntime.InvokeAsync($"{JsType}.tryGetFileAsync(\"{_id}\", \"{WebAssemblyRuntime.EscapeJs(name)}\")");

                if (fileInfoJson == null)
                {
                    throw new FileNotFoundException($"There is no file with name '{name}'.");
                }

                // File exists
                var fileInfo = JsonHelper.Deserialize <NativeStorageItemInfo>(fileInfoJson);

                return(StorageFile.GetFromNativeInfo(fileInfo, Owner));
            }
コード例 #11
0
ファイル: StorageFolder.native.wasm.cs プロジェクト: kcmd/uno
            public override async Task <IStorageItem?> TryGetItemAsync(string name, CancellationToken token)
            {
                var fileInfoJson = await WebAssemblyRuntime.InvokeAsync($"{JsType}.tryGetFileAsync(\"{_id}\", \"{WebAssemblyRuntime.EscapeJs(name)}\")");

                if (fileInfoJson != null)
                {
                    // File exists
                    var fileInfo = JsonHelper.Deserialize <NativeStorageItemInfo>(fileInfoJson);
                    return(StorageFile.GetFromNativeInfo(fileInfo, Owner));
                }

                var folderInfoJson = await WebAssemblyRuntime.InvokeAsync($"{JsType}.tryGetFolderAsync(\"{_id}\", \"{WebAssemblyRuntime.EscapeJs(name)}\")");

                if (folderInfoJson != null)
                {
                    // Folder exists
                    var folderInfo = JsonHelper.Deserialize <NativeStorageItemInfo>(folderInfoJson);
                    return(GetFromNativeInfo(folderInfo, Owner));
                }

                return(null);
            }
コード例 #12
0
ファイル: StorageFolder.native.wasm.cs プロジェクト: kcmd/uno
            public override async Task <StorageFile> CreateFileAsync(string desiredName, CreationCollisionOption option, CancellationToken cancellationToken)
            {
                var actualName = desiredName;

                var existingItem = await TryGetItemAsync(desiredName, cancellationToken);

                switch (option)
                {
                case CreationCollisionOption.ReplaceExisting:
                    if (existingItem is StorageFolder)
                    {
                        throw new UnauthorizedAccessException("There is already a folder with the same name.");
                    }

                    if (existingItem is StorageFile)
                    {
                        // Delete existing file
                        await existingItem.DeleteAsync();
                    }
                    break;

                case CreationCollisionOption.FailIfExists:
                    if (existingItem != null)
                    {
                        throw new UnauthorizedAccessException("There is already an item with the same name.");
                    }
                    break;

                case CreationCollisionOption.OpenIfExists:
                    if (existingItem is StorageFile existingFile)
                    {
                        return(existingFile);
                    }

                    if (existingItem is StorageFolder)
                    {
                        throw new UnauthorizedAccessException("There is already a file with the same name.");
                    }
                    break;

                case CreationCollisionOption.GenerateUniqueName:
                    actualName = await FindAvailableNumberedFileNameAsync(desiredName);

                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(option));
                }

                var newFolderNativeInfo = await WebAssemblyRuntime.InvokeAsync($"{JsType}.createFileAsync(\"{_id}\", \"{WebAssemblyRuntime.EscapeJs(actualName)}\")");

                if (newFolderNativeInfo == null)
                {
                    throw new UnauthorizedAccessException("Could not create file.");
                }

                var info = JsonHelper.Deserialize <NativeStorageItemInfo>(newFolderNativeInfo);

                return(StorageFile.GetFromNativeInfo(info, Owner));
            }
コード例 #13
0
ファイル: StorageFolder.native.wasm.cs プロジェクト: kcmd/uno
            public override async Task <StorageFolder> GetFolderAsync(string name, CancellationToken ct)
            {
                // Handling validation
                // Source: https://docs.microsoft.com/en-us/uwp/api/windows.storage.storagefolder.getfolderasync?view=winrt-19041#exceptions

                if (Uri.IsWellFormedUriString(name, UriKind.RelativeOrAbsolute))
                {
                    throw new ArgumentException("The path cannot be in Uri format (for example, /Assets). Check the value of name.", nameof(name));
                }

                var folderInfoJson = await WebAssemblyRuntime.InvokeAsync($"{JsType}.tryGetFolderAsync(\"{_id}\", \"{WebAssemblyRuntime.EscapeJs(name)}\")");

                if (folderInfoJson == null)
                {
                    throw new FileNotFoundException($"There is no folder with name '{name}'.");
                }

                var info          = JsonHelper.Deserialize <NativeStorageItemInfo>(folderInfoJson);
                var storageFolder = GetFromNativeInfo(info, Owner);

                return(storageFolder);
            }
コード例 #14
0
 partial void DetachVisualPartial()
 {
     WebAssemblyRuntime.InvokeJS($"{JsType}.detachVisual()");
 }
コード例 #15
0
 /// <inheritdoc />
 public void DestroyNativeInstance(IntPtr managedHandle, long jsHandle)
 => WebAssemblyRuntime.InvokeJS($"{_type.FullName}.destroyInstance(\"{managedHandle}\", \"{jsHandle}\")");
コード例 #16
0
 private void ObserveApplicationVisibility()
 {
     WebAssemblyRuntime.InvokeJS("Windows.UI.Xaml.Application.observeVisibility()");
 }
コード例 #17
0
 partial void ObserveSystemThemeChanges()
 {
     WebAssemblyRuntime.InvokeJS("Windows.UI.Xaml.Application.observeSystemTheme()");
 }
コード例 #18
0
        private async Task <StorageFile?> NativePickerPickSaveFileAsync(CancellationToken token)
        {
            var showAllEntryParameter = "true";
            var fileTypeMapParameter  = JsonHelper.Serialize(BuildFileTypesMap());

            var promise = $"{JsType}.nativePickSaveFileAsync({showAllEntryParameter},'{WebAssemblyRuntime.EscapeJs(fileTypeMapParameter)}')";
            var nativeStorageItemInfo = await WebAssemblyRuntime.InvokeAsync(promise);

            if (nativeStorageItemInfo is null)
            {
                return(null);
            }

            var info = JsonHelper.Deserialize <NativeStorageItemInfo>(nativeStorageItemInfo);

            return(StorageFile.GetFromNativeInfo(info));
        }
コード例 #19
0
 protected override void SetStartFrameDelay(long delayMs) => WebAssemblyRuntime.InvokeJSWithInterop($"{this}.SetStartFrameDelay({delayMs});");
コード例 #20
0
 internal FFmpegFileStream(string fileName, string mode)
 {
     if (!FFmpeg.Loaded)
     {
         throw new InvalidOperationException("Cannot use FFmpegFileStream before initializing FFmpeg.");
     }
     uuid          = System.Guid.NewGuid().ToString();
     this.fileName = fileName;
     WebAssemblyRuntime.InvokeJS($@"fileStreams['{uuid}'] = ffmpeg.FS('open', '{WebAssemblyRuntime.EscapeJs(fileName)}', '{mode}')");
     canWrite = mode.Contains("r");
     canRead  = mode.Contains("w");
 }
コード例 #21
0
 /// <inheritdoc />
 public void DestroyNativeInstance(IntPtr managedHandle, long jsHandle)
 => WebAssemblyRuntime.InvokeJS($"Windows.UI.Xaml.Media.Animation.RenderingLoopFloatAnimator.destroyInstance(\"{managedHandle}\", \"{jsHandle}\")");
コード例 #22
0
ファイル: Window.wasm.cs プロジェクト: dpisanu/Uno
 private void InternalActivate()
 {
     WebAssemblyRuntime.InvokeJS("Uno.UI.WindowManager.current.activate();");
 }
コード例 #23
0
        partial void StopDpiChanged()
        {
            var command = $"{JsType}.stopDpiChanged()";

            WebAssemblyRuntime.InvokeJS(command);
        }
コード例 #24
0
 public void RequestAnimationFrame(bool renderLoop) =>
 WebAssemblyRuntime.InvokeJSWithInterop($"{this}.requestAnimationFrame({(renderLoop ? "true" : "false")});");
コード例 #25
0
 private static string ReadJsString(string property) => WebAssemblyRuntime.InvokeJS(property);
コード例 #26
0
 public void SetEnableRenderLoop(bool enable) =>
 WebAssemblyRuntime.InvokeJSWithInterop($"{this}.setEnableRenderLoop({(enable ? "true" : "false")});");
コード例 #27
0
        private bool IsNativePickerSupported()
        {
            var isSupportedString = WebAssemblyRuntime.InvokeJS($"{JsType}.isNativeSupported()");

            return(bool.TryParse(isSupportedString, out var isSupported) && isSupported);
        }
コード例 #28
0
 public void ResizeCanvas() =>
 WebAssemblyRuntime.InvokeJSWithInterop($"{this}.resizeCanvas();");
コード例 #29
0
        private void CapturePointerNative(Pointer pointer)
        {
            var command = "Uno.UI.WindowManager.current.setPointerCapture(" + HtmlId + ", " + pointer.PointerId + ");";

            WebAssemblyRuntime.InvokeJS(command);
        }
コード例 #30
0
        public static async Task <Stream> MergeToFileAsync(string video, string audio, string output)
        {
            await WebAssemblyRuntime.InvokeAsync($@"
                ffmpeg.run('-i', '{WebAssemblyRuntime.EscapeJs(video)}', '-i', '{WebAssemblyRuntime.EscapeJs(audio)}', '-c', 'copy', '{WebAssemblyRuntime.EscapeJs(output)}');");

            return(FFmpegFile.OpenRead(output));
        }