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)); }
private void ReleasePointerCaptureNative(Pointer pointer) { var command = "Uno.UI.WindowManager.current.releasePointerCapture(\"" + HtmlId + "\", " + pointer.PointerId + ");"; WebAssemblyRuntime.InvokeJS(command); }
private static void StopContentChanged() { var command = $"{JsType}.stopContentChanged()"; WebAssemblyRuntime.InvokeJS(command); }
partial void DeactivateScreenLock() { var command = $"{JsType}.deactivateScreenLock()"; WebAssemblyRuntime.InvokeJS(command); }
private static bool TryReadJsFloat(string property, out float value) => float.TryParse(WebAssemblyRuntime.InvokeJS(property), out value);
protected override void DisableFrameReporting() => WebAssemblyRuntime.InvokeJSWithInterop($"{this}.DisableFrameReporting();");
protected override void SetAnimationFramesInterval() => WebAssemblyRuntime.InvokeJSWithInterop($"{this}.SetAnimationFramesInterval();");
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}"); } }
partial void DisposeNative() { var removeInstanceCommand = $"{JsType}.removePort('{_managedId}')"; WebAssemblyRuntime.InvokeJS(removeInstanceCommand); }
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)); }
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); }
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)); }
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); }
partial void DetachVisualPartial() { WebAssemblyRuntime.InvokeJS($"{JsType}.detachVisual()"); }
/// <inheritdoc /> public void DestroyNativeInstance(IntPtr managedHandle, long jsHandle) => WebAssemblyRuntime.InvokeJS($"{_type.FullName}.destroyInstance(\"{managedHandle}\", \"{jsHandle}\")");
private void ObserveApplicationVisibility() { WebAssemblyRuntime.InvokeJS("Windows.UI.Xaml.Application.observeVisibility()"); }
partial void ObserveSystemThemeChanges() { WebAssemblyRuntime.InvokeJS("Windows.UI.Xaml.Application.observeSystemTheme()"); }
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)); }
protected override void SetStartFrameDelay(long delayMs) => WebAssemblyRuntime.InvokeJSWithInterop($"{this}.SetStartFrameDelay({delayMs});");
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"); }
/// <inheritdoc /> public void DestroyNativeInstance(IntPtr managedHandle, long jsHandle) => WebAssemblyRuntime.InvokeJS($"Windows.UI.Xaml.Media.Animation.RenderingLoopFloatAnimator.destroyInstance(\"{managedHandle}\", \"{jsHandle}\")");
private void InternalActivate() { WebAssemblyRuntime.InvokeJS("Uno.UI.WindowManager.current.activate();"); }
partial void StopDpiChanged() { var command = $"{JsType}.stopDpiChanged()"; WebAssemblyRuntime.InvokeJS(command); }
public void RequestAnimationFrame(bool renderLoop) => WebAssemblyRuntime.InvokeJSWithInterop($"{this}.requestAnimationFrame({(renderLoop ? "true" : "false")});");
private static string ReadJsString(string property) => WebAssemblyRuntime.InvokeJS(property);
public void SetEnableRenderLoop(bool enable) => WebAssemblyRuntime.InvokeJSWithInterop($"{this}.setEnableRenderLoop({(enable ? "true" : "false")});");
private bool IsNativePickerSupported() { var isSupportedString = WebAssemblyRuntime.InvokeJS($"{JsType}.isNativeSupported()"); return(bool.TryParse(isSupportedString, out var isSupported) && isSupported); }
public void ResizeCanvas() => WebAssemblyRuntime.InvokeJSWithInterop($"{this}.resizeCanvas();");
private void CapturePointerNative(Pointer pointer) { var command = "Uno.UI.WindowManager.current.setPointerCapture(" + HtmlId + ", " + pointer.PointerId + ");"; WebAssemblyRuntime.InvokeJS(command); }
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)); }