public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("signLanguage/recordedVideo", HandleRecordedVideoRequest, true); apiHandler.RegisterEndpointHandler("signLanguage/deleteVideo", HandleDeleteVideoRequest, true); apiHandler.RegisterEndpointHandler("signLanguage/importVideo", HandleImportVideoRequest, true); apiHandler.RegisterEndpointHandler("signLanguage/getStats", HandleVideoStatisticsRequest, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { // HandleStartRecording seems to need to be on the UI thread in order for HandleEndRecord() to detect the correct state. apiHandler.RegisterEndpointHandler("audio/startRecord", HandleStartRecording, true).Measureable(); // Note: This handler locks and unlocks a shared resource (_completeRecording lock). // Any other handlers depending on this resource should not wait on the same thread (i.e. the UI thread) or deadlock can occur. apiHandler.RegisterEndpointHandler("audio/endRecord", HandleEndRecord, true).Measureable(); // Any handler which retrieves information from the audio folder SHOULD wait on the _completeRecording lock (call WaitForRecordingToComplete()) to ensure that it sees // a consistent state of the audio folder, and therefore should NOT run on the UI thread. // Also, explicitly setting requiresSync to true (even tho that's default anyway) to make concurrency less complicated to think about apiHandler.RegisterEndpointHandler("audio/checkForAnyRecording", HandleCheckForAnyRecording, false, true); apiHandler.RegisterEndpointHandler("audio/checkForAllRecording", HandleCheckForAllRecording, false, true); apiHandler.RegisterEndpointHandler("audio/deleteSegment", HandleDeleteSegment, false, true); apiHandler.RegisterEndpointHandler("audio/checkForSegment", HandleCheckForSegment, false, true); apiHandler.RegisterEndpointHandler("audio/wavFile", HandleAudioFileRequest, false, true); // Doesn't matter whether these are on UI thread or not, so using the old default which was true apiHandler.RegisterEndpointHandler("audio/currentRecordingDevice", HandleCurrentRecordingDevice, true); apiHandler.RegisterEndpointHandler("audio/devices", HandleAudioDevices, true); apiHandler.RegisterEndpointHandler("audio/copyAudioFile", HandleCopyAudioFile, false); Debug.Assert(BloomServer.portForHttp > 0, "Need the server to be listening before this can be registered (BL-3337)."); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler(kApiUrlPart + "list", HandleListRequest, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "name", request => { // always null? request.ReplyWithText(_collection.Name); request.ReplyWithText(_settings.CollectionName); }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "books", HandleBooksRequest, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "book", HandleThumbnailRequest, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "selected-book-id", request => { switch (request.HttpMethod) { case HttpMethods.Get: request.ReplyWithText("" + _libraryModel.GetSelectedBookOrNull()?.ID); break; case HttpMethods.Post: var book = GetBookObjectFromPost(request); _libraryModel.SelectBook(book); request.PostSucceeded(); break; } }, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("signLanguage/recordedVideo", HandleRecordedVideoRequest, true).Measureable("Process recorded video"); apiHandler.RegisterEndpointHandler("signLanguage/deleteVideo", HandleDeleteVideoRequest, true).Measureable("Delete video");; apiHandler.RegisterEndpointHandler("signLanguage/importVideo", HandleImportVideoRequest, true); // has dialog, so measure internally after the dialog. apiHandler.RegisterEndpointHandler("signLanguage/getStats", HandleVideoStatisticsRequest, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler(kApiUrlPart + "checkAutoSegmentDependencies", CheckAutoSegmentDependenciesMet, handleOnUiThread: false, requiresSync: false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "autoSegmentAudio", AutoSegment, handleOnUiThread: false, requiresSync: false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "getForcedAlignmentTimings", GetForcedAlignmentTimings, handleOnUiThread: false, requiresSync: false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "eSpeakPreview", ESpeakPreview, handleOnUiThread: false, requiresSync: false); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { // Must not require sync, because it launches a Bloom dialog, which will make other api requests // that will be blocked if this is locked. apiHandler.RegisterEndpointHandler("bookCommand/exportToSpreadsheet", (request) => { _spreadsheetApi.ShowExportToSpreadsheetUI(GetBookObjectFromPost(request)); request.PostSucceeded(); }, true, false); apiHandler.RegisterEndpointHandler("bookCommand/enhanceLabel", (request) => { // We want this to be fast...many things are competing for api handling threads while // Bloom is starting up, including many buttons sending this request... // so we'll postpone until idle even searching for the right BookInfo. var collection = request.RequiredParam("collection-id").Trim(); var id = request.RequiredParam("id"); RequestButtonLabelUpdate(collection, id); request.PostSucceeded(); }, false, false); apiHandler.RegisterBooleanEndpointHandler("bookCommand/decodable", request => { return(_collectionModel.IsBookDecodable); }, (request, b) => { _collectionModel.SetIsBookDecodable(b); }, true); apiHandler.RegisterBooleanEndpointHandler("bookCommand/leveled", request => { return(_collectionModel.IsBookLeveled); }, (request, b) => { _collectionModel.SetIsBookLeveled(b); }, true); apiHandler.RegisterEndpointLegacy("bookCommand/", HandleBookCommand, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { // We could probably get away with using the server thread here, but the code interacts quite a bit with the // current book and other state. apiHandler.RegisterEndpointHandler("pageTemplates", HandleTemplatesRequest, true); // Being on the UI thread causes a deadlock on Linux/Mono. See https://silbloom.myjetbrains.com/youtrack/issue/BL-3818. apiHandler.RegisterEndpointHandler("pageTemplateThumbnail", HandleThumbnailRequest, false); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("pageList/pages", HandlePagesRequest, false); apiHandler.RegisterEndpointHandler("pageList/pageContent", HandlePageContentRequest, false); apiHandler.RegisterEndpointHandler("pageList/pageMoved", HandlePageMovedRequest, true); apiHandler.RegisterEndpointHandler("pageList/pageClicked", HandlePageClickedRequest, true); apiHandler.RegisterEndpointHandler("pageList/menuClicked", HandleShowMenuRequest, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("editView/setModalState", HandleSetModalState, true); apiHandler.RegisterEndpointHandler("editView/chooseWidget", HandleChooseWidget, true); apiHandler.RegisterEndpointHandler("editView/getBookColors", HandleGetColors, true); apiHandler.RegisterEndpointHandler("editView/editPagePainted", HandleEditPagePainted, true); apiHandler.RegisterEndpointHandler("editView/saveToolboxSetting", HandleSaveToolboxSetting, true); apiHandler.RegisterEndpointHandler("editView/setTopic", HandleSetTopic, true); apiHandler.RegisterEndpointHandler("editView/isTextSelected", HandleIsTextSelected, false); apiHandler.RegisterEndpointHandler("editView/getBookLangs", HandleGetBookLangs, false); apiHandler.RegisterEndpointHandler("editView/requestTranslationGroupContent", RequestDefaultTranslationGroupContent, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("dialog/close", (ApiRequest request) => { BrowserDialog.CurrentDialog?.Close(); request.PostSucceeded(); }, true); }
public static void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("help/.*", (request) => { var topic = request.LocalPath().Replace("api/help", ""); Show(Application.OpenForms.Cast <Form>().Last(), topic); //if this is called from a simple html anchor, we don't want the browser to do anything request.ExternalLinkSucceeded(); }, true); // opening a form, definitely UI thread }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("performance/showCsvFile", (request) => { Process.Start(_csvFilePath); request.PostSucceeded(); }, false); apiHandler.RegisterEndpointHandler("performance/applicationInfo", (request) => { request.ReplyWithText($"Bloom {Shell.GetShortVersionInfo()} {ApplicationUpdateSupport.ChannelName}"); }, false); apiHandler.RegisterEndpointHandler("performance/allMeasurements", (request) => { List <object> l = new List <object>(); foreach (var measurement in _measurements) { l.Add(measurement.GetSummary()); } request.ReplyWithJson(l.ToArray()); }, false); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("keyboarding/useLongpress", (ApiRequest request) => { try { //detect if some keyboarding system is active, e.g. KeyMan. If it is, don't enable LongPress var form = Application.OpenForms.Cast <Form>().Last(); request.ReplyWithText(SIL.Windows.Forms.Keyboarding.KeyboardController.IsFormUsingInputProcessor(form) ? "false" : "true"); } catch (Exception error) { request.ReplyWithText("true"); // This is arbitrary. I don't know if it's better to assume keyman, or not. NonFatalProblem.Report(ModalIf.None, PassiveIf.All, "Error checking for keyman", "", error); } }, handleOnUiThread: false); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler(kApiUrlPart + "save", request => { { string suggestedName = string.Format("{0}-{1}.epub", Path.GetFileName(_bookSelection.CurrentSelection.FolderPath), _bookSelection.CurrentSelection.BookData.Language1.GetNameInLanguage("en")); using (var dlg = new DialogAdapters.SaveFileDialogAdapter()) { if (!string.IsNullOrEmpty(_lastDirectory) && Directory.Exists(_lastDirectory)) { dlg.InitialDirectory = _lastDirectory; } dlg.FileName = suggestedName; dlg.Filter = "EPUB|*.epub"; dlg.OverwritePrompt = true; if (DialogResult.OK == dlg.ShowDialog()) { _lastDirectory = Path.GetDirectoryName(dlg.FileName); lock (_epubMakerLock) { _pendingSaveAsPath = dlg.FileName; if (!_stagingEpub) { // we can do it right now. No need to check version etc., because anything // that will change the epub we want to save will immediately trigger a new // preview, and we will be staging it until we have it. SaveAsEpub(); } // If we ARE in the middle of staging the epub...quite possible since this // handler is registered with permission to execute in parallel with other // API handlers, the user just has to click Save before the preview is finished... // then we need not do any more here. A call to SaveAsEpub at the end of the // preview generation process will pick up the pending request in _pendingSaveAsPath // and complete the Save. } ReportProgress(LocalizationManager.GetString("PublishTab.Epub.Done", "Done")); ReportAnalytics("Save ePUB"); } } request.PostSucceeded(); } }, true, false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "epubSettings", request => { if (request.HttpMethod == HttpMethods.Get) { request.ReplyWithJson(GetEpubSettings()); } else { // post is deprecated. throw new ApplicationException("epubSettings POST is deprecated"); } }, false); // The backend here was written with an enum that had two choices for how to publish descriptions, but we only ever // have used one of them so far in the UI. So this is a boolean api that converts to an enum underlying value. apiHandler.RegisterBooleanEndpointHandler(kApiUrlPart + "imageDescriptionSetting", request => request.CurrentBook.BookInfo.MetaData.Epub_HowToPublishImageDescriptions == BookInfo.HowToPublishImageDescriptions.OnPage, (request, onPage) => { request.CurrentBook.BookInfo.MetaData.Epub_HowToPublishImageDescriptions = onPage ? BookInfo.HowToPublishImageDescriptions.OnPage : BookInfo.HowToPublishImageDescriptions.None; request.CurrentBook.BookInfo.Save(); var newSettings = _desiredEpubSettings.Clone(); newSettings.howToPublishImageDescriptions = request.CurrentBook.BookInfo.MetaData.Epub_HowToPublishImageDescriptions; RefreshPreview(newSettings); }, false); // Saving a checkbox setting that the user ticks to say "Use my E-reader's font sizes" apiHandler.RegisterBooleanEndpointHandler(kApiUrlPart + "removeFontSizesSetting", request => request.CurrentBook.BookInfo.MetaData.Epub_RemoveFontSizes, (request, booleanSetting) => { request.CurrentBook.BookInfo.MetaData.Epub_RemoveFontSizes = booleanSetting; request.CurrentBook.BookInfo.Save(); var newSettings = _desiredEpubSettings.Clone(); newSettings.removeFontSizes = booleanSetting; RefreshPreview(newSettings); }, false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "updatePreview", request => { RefreshPreview(_desiredEpubSettings); request.PostSucceeded(); }, false); // in fact, must NOT be on UI thread apiHandler.RegisterEndpointHandler(kApiUrlPart + "abortPreview", request => { AbortMakingEpub(); request.PostSucceeded(); }, false, false); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { bool requiresSync = false; // Lets us open the dialog while the epub preview is being generated apiHandler.RegisterEndpointHandler("book/metadata", HandleBookMetadata, false, requiresSync); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler(kApiUrlPart + "bookName", request => { request.ReplyWithText(request.CurrentBook.TitleBestForUserDisplay); }, false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "showAccessibilityChecker", request => { AccessibilityCheckWindow.StaticShow(() => _webSocketServer.SendEvent(kWebSocketContext, kWindowActivated)); request.PostSucceeded(); }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "descriptionsForAllImages", request => { var problems = AccessibilityCheckers.CheckDescriptionsForAllImages(request.CurrentBook); var resultClass = problems.Any() ? "failed" : "passed"; request.ReplyWithJson(new { resultClass = resultClass, problems = problems }); }, false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "audioForAllImageDescriptions", request => { var problems = AccessibilityCheckers.CheckAudioForAllImageDescriptions(request.CurrentBook); var resultClass = problems.Any() ? "failed" : "passed"; request.ReplyWithJson(new { resultClass = resultClass, problems = problems }); }, false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "audioForAllText", request => { var problems = AccessibilityCheckers.CheckAudioForAllText(request.CurrentBook); var resultClass = problems.Any() ? "failed" : "passed"; request.ReplyWithJson(new { resultClass = resultClass, problems = problems }); }, false); // Just a checkbox that the user ticks to say "yes, I checked this" // At this point, we don't have a way to clear that when the book changes. apiHandler.RegisterBooleanEndpointHandler(kApiUrlPart + "noEssentialInfoByColor", request => request.CurrentBook.BookInfo.MetaData.A11y_NoEssentialInfoByColor, (request, b) => { request.CurrentBook.BookInfo.MetaData.A11y_NoEssentialInfoByColor = b; request.CurrentBook.Save(); }, false); // Just a checkbox that the user ticks to say "yes, I checked this" // At this point, we don't have a way to clear that when the book changes. apiHandler.RegisterBooleanEndpointHandler(kApiUrlPart + "noTextIncludedInAnyImages", request => request.CurrentBook.BookInfo.MetaData.A11y_NoTextIncludedInAnyImages, (request, b) => { request.CurrentBook.BookInfo.MetaData.A11y_NoTextIncludedInAnyImages = b; request.CurrentBook.Save(); }, false); //enhance: this might have to become async to work on large books on slow computers apiHandler.RegisterEndpointHandler(kApiUrlPart + "aceByDaisyReportUrl", request => { MakeAceByDaisyReport(request); }, false, false ); // A checkbox that the user ticks in the Accessible Image tool to request a preview // of how things might look with cataracts. // For now this doesn't seem worth persisting, except for the session so it sticks from page to page. apiHandler.RegisterBooleanEndpointHandler(kApiUrlPart + "cataracts", request => _simulateCataracts, (request, b) => { _simulateCataracts = b; }, false); // A checkbox that the user ticks in the Accessible Image tool to request a preview // of how things might look with color-blindness, and a set of radio buttons // for choosing different kinds of color-blindness. // For now these doesn't seem worth persisting, except for the session so it sticks from page to page. apiHandler.RegisterBooleanEndpointHandler(kApiUrlPart + "colorBlindness", request => _simulateColorBlindness, (request, b) => { _simulateColorBlindness = b; }, false); apiHandler.RegisterEnumEndpointHandler(kApiUrlPart + "kindOfColorBlindness", request => _kindOfColorBlindness, (request, kind) => _kindOfColorBlindness = kind, false); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler(kApiUrlPart + "recordVideo", request => { RecordVideo(request); request.PostSucceeded(); }, true, false); // This is sent directly from BloomPlayer when it gets to the end of making the recording. // The player gives Bloom a list of all the sounds it played and their timings so we can // merge them into the captured video. apiHandler.RegisterEndpointHandler(kApiUrlPart + "soundLog", request => { var soundLog = request.RequiredPostJson(); _recordVideoWindow.StopRecording(soundLog); request.PostSucceeded(); }, true, false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "playVideo", request => { _recordVideoWindow.PlayVideo(); request.PostSucceeded(); }, true, false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "settings", request => { if (request.HttpMethod == HttpMethods.Get) { var settings = request.CurrentBook.BookInfo.PublishSettings.AudioVideo; var lastPageIndex = request.CurrentBook.GetPages().Count() - 1; // this default might be too high but I don't think it will ever be too low. // The HTML side will handle it being too high. var pageRange = new[] { 0, lastPageIndex }; if (settings.PageRange != null && settings.PageRange.Length == 2) { // I wanted to do something like this as validation, in case the book changed // since we saved. But we don't have an accurate page count of the modified version // of the book that the range applies to yet. (e.g., switch to device xmatter, strip // activities,... //pageRange[1] = Math.Min(settings.PageRange[1], lastPageIndex); // not more than the pages we have //pageRange[0] = Math.Min(settings.PageRange[0], pageRange[1] - 1); // at least one less than lim //if (pageRange[0] < 0) // pageRange[0] = 0; //if (pageRange[1] < pageRange[0] + 1) // pageRange[1] = Math.Min(pageRange[0] + 1, lastPageIndex); pageRange = settings.PageRange; } request.ReplyWithJson(new { format = settings.Format, pageTurnDelay = settings.PageTurnDelayDouble, motion = settings.Motion, pageRange }); } else { var data = DynamicJson.Parse(request.RequiredPostJson()); var settings = request.CurrentBook.BookInfo.PublishSettings.AudioVideo; var oldMotion = settings.Motion; settings.Format = data.format; settings.PageTurnDelayDouble = data.pageTurnDelay; settings.Motion = data.motion; // pageRange also comes in as doubles. "as double[]" does not work, so have to do them individually. settings.PageRange = new int[0]; // Typescript passes an empty array if all pages are selected. // This allows us naturally to keep everything selected until the user explicitly changes something. if (data.pageRange.IsArray && data.pageRange.Count == 2) { var start = (int)data.pageRange[0]; var end = (int)data.pageRange[1]; settings.PageRange = new[] { start, end }; } request.CurrentBook.BookInfo.SavePublishSettings(); _recordVideoWindow?.SetPageReadTime(settings.PageTurnDelayDouble.ToString()); _recordVideoWindow?.SetFormat(request.CurrentBook.BookInfo.PublishSettings.AudioVideo.Format, ShouldRecordAsLandscape(request.CurrentBook), request.CurrentBook.GetLayout()); if (settings.Motion != oldMotion) { UpdatePreview(request); // does its own success/fail } else { request.PostSucceeded(); } } }, true, false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "videoSettings", request => { if (request.HttpMethod == HttpMethods.Get) { request.ReplyWithText(request.CurrentBook.BookInfo.PublishSettings.AudioVideo.PlayerSettings ?? ""); } else { request.CurrentBook.BookInfo.PublishSettings.AudioVideo.PlayerSettings = request.RequiredPostString(); request.CurrentBook.BookInfo.SavePublishSettings(); request.PostSucceeded(); } }, true, false); apiHandler.RegisterBooleanEndpointHandler(kApiUrlPart + "hasActivities", request => { return(request.CurrentBook.HasActivities); }, null, // no write action false, true); // we don't really know, just safe default // Returns true if publish to MP3 is supported for this book, false otherwise. // To be eligible to publish to MP3, the book must contain narration audio. // (There's not any point to an MP3 if the book has absolutely no audio... // Even a book with background music but no narration, there's not too much point to an MP3 either) apiHandler.RegisterBooleanEndpointHandler(kApiUrlPart + "isMP3FormatSupported", request => { // ENHANCE: If desired, you can make it only consider languages in the book that are currently relevant, // instead of any language in the book. var narrationAudioLangs = request.CurrentBook.GetLanguagesWithAudio(); return(narrationAudioLangs.Any()); }, null, false, false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "startRecording", request => { var videoList = request.GetPostStringOrNull(); var anyVideoHasAudio = _recordVideoWindow?.AnyVideoHasAudio(videoList, request.CurrentBook.FolderPath) ?? false; if (anyVideoHasAudio) { var messageBoxButtons = new[] { new MessageBoxButton() { Text = LocalizationManager.GetString("Common.Continue", "Continue"), Id = "continue" }, new MessageBoxButton() { Text = LocalizationManager.GetString("Common.Cancel", "Cancel"), Id = "cancel", Default = true } }; if (BloomMessageBox.Show(null, LocalizationManager.GetString("PublishTab.RecordVideo.NoAudioInVideo", "Currently, Bloom does not support including audio from Sign Language videos in video output."), messageBoxButtons) == "cancel") { request.Failed("canceled"); _recordVideoWindow.Close(); return; } } _recordVideoWindow?.StartFfmpegForVideoCapture(); request.PostSucceeded(); }, true, false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "shouldUseOriginalPageSize", request => { RecordVideoWindow.GetDataForFormat(request.CurrentBook.BookInfo.PublishSettings.AudioVideo.Format, ShouldRecordAsLandscape(request.CurrentBook), request.CurrentBook.GetLayout(), out _, out _, out _, out bool useOriginalPageSize); request.ReplyWithBoolean(useOriginalPageSize); }, true, // has to be on UI thread because it uses Bloom's main window to find the right screen false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "tooBigForScreenMsg", request => { request.ReplyWithText(RecordVideoWindow.GetDataForFormat(request.CurrentBook.BookInfo.PublishSettings.AudioVideo.Format, ShouldRecordAsLandscape(request.CurrentBook), request.CurrentBook.GetLayout(), out _, out _, out _, out _)); }, true, // has to be on UI thread because it uses Bloom's main window to find the right screen false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "saveVideo", request => { if (_recordVideoWindow == null) { // This shouldn't be possible, but just in case, we'll kick off the recording now. RecordVideo(request); } _recordVideoWindow?.SetBook(request.CurrentBook); // If we bring up the dialog inside this API call, it may time out. Application.Idle += SaveVideoOnIdle; request.PostSucceeded(); }, true, false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "updatePreview", request => { UpdatePreview(request); }, false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "displaySettings", request => { Process.Start("desk.cpl"); request.PostSucceeded(); }, false); apiHandler.RegisterBooleanEndpointHandler(kApiUrlPart + "isScalingActive", request => IsScalingActive(), null, true); }
public static void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("toolbox/settings", HandleSettings, false); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("editView/setModalState", HandleSetModalState, true); apiHandler.RegisterEndpointHandler("editView/chooseWidget", HandleChooseWidget, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler(kApiUrlPart + "requestState", request => { if (request.HttpMethod == HttpMethods.Get) { request.ReplyWithJson(CurrentStateString); } else // post { Debug.Fail("We shouldn't ever be using the 'post' version."); request.PostSucceeded(); } }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "addPage", request => { AddPageButton_Click(); request.PostSucceeded(); }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "duplicatePage", request => { _editingModel.OnDuplicatePage(); request.PostSucceeded(); }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "deletePage", request => { if (ConfirmRemovePageDialog.Confirm()) { _editingModel.OnDeletePage(); } request.PostSucceeded(); }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "lockBook", request => { _editingModel.SaveNow(); // BL-5421 lock and unlock lose typing _editingModel.CurrentBook.TemporarilyUnlocked = false; request.PostSucceeded(); UpdateState(); // because we aren't selecting a new page _editingModel.RefreshDisplayOfCurrentPage(); }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "unlockBook", request => { _editingModel.SaveNow(); // BL-5421 lock and unlock lose typing _editingModel.CurrentBook.TemporarilyUnlocked = true; request.PostSucceeded(); UpdateState(); // because we aren't selecting a new page _editingModel.RefreshDisplayOfCurrentPage(); }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "cleanup", request => { SendCleanupState(); request.PostSucceeded(); }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "zoomMinus", request => { _editingModel.AdjustPageZoom(-10); request.PostSucceeded(); }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "zoomPlus", request => { _editingModel.AdjustPageZoom(10); request.PostSucceeded(); }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "requestVideoPlaceHolder", request => { _editingModel.RequestVideoPlaceHolder(); request.PostSucceeded(); }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "requestWidgetPlaceHolder", request => { _editingModel.RequestWidgetPlaceHolder(); request.PostSucceeded(); }, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("toolbox/enabledTools", HandleEnabledToolsRequest, true); apiHandler.RegisterEndpointHandler("toolbox/fileExists", HandleFileExistsRequest, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { // Both of these display UI, expect to require UI thread. apiHandler.RegisterEndpointHandler("addPage", HandleAddPage, true).Measureable("Add Page"); apiHandler.RegisterEndpointHandler("changeLayout", HandleChangeLayout, true).Measureable("Change Layout");; }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("copyrightAndLicense/ccImage", HandleGetCCImage, false); apiHandler.RegisterEndpointHandler("copyrightAndLicense/bookCopyrightAndLicense", HandleBookCopyrightAndLicense, true); apiHandler.RegisterEndpointHandler("copyrightAndLicense/imageCopyrightAndLicense", HandleImageCopyrightAndLicense, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("teamCollection/repoFolderPath", HandleRepoFolderPath, false); apiHandler.RegisterEndpointHandler("teamCollection/isTeamCollectionEnabled", HandleIsTeamCollectionEnabled, false); apiHandler.RegisterEndpointHandler("teamCollection/bookStatus", HandleBookStatus, false); apiHandler.RegisterEndpointHandler("teamCollection/selectedBookStatus", HandleSelectedBookStatus, false); apiHandler.RegisterEndpointHandler("teamCollection/attemptLockOfCurrentBook", HandleAttemptLockOfCurrentBook, true); apiHandler.RegisterEndpointHandler("teamCollection/checkInCurrentBook", HandleCheckInCurrentBook, true); apiHandler.RegisterEndpointHandler("teamCollection/forgetChangesInSelectedBook", HandleForgetChangesInSelectedBook, true); apiHandler.RegisterEndpointHandler("teamCollection/chooseFolderLocation", HandleChooseFolderLocation, true); apiHandler.RegisterEndpointHandler("teamCollection/createTeamCollection", HandleCreateTeamCollection, true); apiHandler.RegisterEndpointHandler("teamCollection/joinTeamCollection", HandleJoinTeamCollection, true); apiHandler.RegisterEndpointHandler("teamCollection/getLog", HandleGetLog, false); apiHandler.RegisterEndpointHandler("teamCollection/getCollectionName", HandleGetCollectionName, false); apiHandler.RegisterEndpointHandler("teamCollection/showCreateTeamCollectionDialog", HandleShowCreateTeamCollectionDialog, true); apiHandler.RegisterEndpointHandler("teamCollection/reportBadZip", HandleReportBadZip, true); apiHandler.RegisterEndpointHandler("teamCollection/showRegistrationDialog", HandleShowRegistrationDialog, true, false); apiHandler.RegisterEndpointHandler("teamCollection/getHistory", HandleGetHistory, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("fileIO/chooseFile", ChooseFile, true); apiHandler.RegisterEndpointHandler("fileIO/getSpecialLocation", GetSpecialLocation, true); apiHandler.RegisterEndpointHandler("fileIO/copyFile", CopyFile, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { // ProblemDialog.tsx uses this endpoint to get the screenshot image. apiHandler.RegisterEndpointHandler("problemReport/screenshot", (ApiRequest request) => { if (_screenshotTempFile == null) { request.Failed(); } else { request.ReplyWithImage(_screenshotTempFile.Path); } }, true); // ProblemDialog.tsx uses this endpoint to get the name of the book. apiHandler.RegisterEndpointHandler("problemReport/bookName", (ApiRequest request) => { var bestBookName = _bookSelection.CurrentSelection?.TitleBestForUserDisplay; request.ReplyWithText(bestBookName ?? "??"); }, true); // ProblemDialog.tsx uses this endpoint to get the registered user's email address. apiHandler.RegisterEndpointHandler("problemReport/emailAddress", (ApiRequest request) => { request.ReplyWithText(SIL.Windows.Forms.Registration.Registration.Default.Email); }, true); // PrivacyScreen.tsx uses this endpoint to show the user what info will be included in the report. apiHandler.RegisterEndpointHandler("problemReport/diagnosticInfo", (ApiRequest request) => { var userWantsToIncludeBook = request.RequiredParam("includeBook") == "true"; var userInput = request.RequiredParam("userInput"); var userEmail = request.RequiredParam("email"); request.ReplyWithText(GetDiagnosticInfo(userWantsToIncludeBook, userInput, userEmail)); }, true); // ProblemDialog.tsx uses this endpoint in its AttemptSubmit method; // it expects a response that it will use to show the issue link to the user. apiHandler.RegisterEndpointHandler("problemReport/submit", (ApiRequest request) => { var report = DynamicJson.Parse(request.RequiredPostJson()); var subject = report.kind == "User" ? "User Problem" : report.kind == "Fatal" ? "Crash Report" : "Error Report"; var issueSubmission = new YouTrackIssueSubmitter(YouTrackProjectKey); var userDesc = report.userInput as string; var userEmail = report.email as string; if (report.includeScreenshot && _screenshotTempFile != null && RobustFile.Exists(_screenshotTempFile.Path)) { issueSubmission.AddAttachmentWhenWeHaveAnIssue(_screenshotTempFile.Path); } var diagnosticInfo = GetDiagnosticInfo(report.includeBook, userDesc, userEmail); if (!string.IsNullOrWhiteSpace(userEmail)) { // remember their email SIL.Windows.Forms.Registration.Registration.Default.Email = userEmail; } const string failureResult = "failed"; string issueId; try { issueId = issueSubmission.SubmitToYouTrack(subject, diagnosticInfo); } catch (Exception e) { Debug.Fail("Submitting problem report to YouTrack failed with '" + e.Message + "'."); issueId = failureResult; } object linkToNewIssue; if (issueId == failureResult) { var zipPath = MakeEmailableReportFile(report.includeBook, report.includeScreenshot, userDesc, diagnosticInfo); linkToNewIssue = new { issueLink = failureResult + ":" + zipPath }; } else { linkToNewIssue = new { issueLink = "https://issues.bloomlibrary.org/youtrack/issue/" + issueId }; if (report.includeBook) { try { string zipPath = CreateBookZipFile(issueId, userDesc); if (zipPath != null) { issueSubmission.AttachFileToExistingIssue(issueId, zipPath); } } catch (Exception error) { Debug.WriteLine($"Attaching book to new YouTrack issue failed with '{error.Message}'."); var msg = "***Error as ProblemReportApi attempted to upload the zipped book: " + error.Message; userDesc += Environment.NewLine + msg; Logger.WriteEvent(userDesc); _bookZipFileTemp.Detach(); } } } request.ReplyWithJson(linkToNewIssue); }, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler("workspace/openOrCreateCollection/", HandleOpenOrCreateCollection, true); }
private static IEnumerable <string> _additionalPathsToInclude; // typically a problem image file public void RegisterWithApiHandler(BloomApiHandler apiHandler) { // This one is an exception: it's not used BY the problem report dialog, but to launch one // from Javascript. However, it also must not require the lock, because if it holds it, // no calls that need it can run (such as one put forth by the Cancel button). apiHandler.RegisterEndpointLegacy("problemReport/showDialog", HandleShowDialog, true, false); // Similarly, but this launches from a button shown in Book.ErrorDom apiHandler.RegisterEndpointHandler("problemReport/unreadableBook", HandleUnreadableBook, true, false); // For the paranoid - We could also have showProblemReport block these handlers while _reportInfo is being populated. // I think it's unnecessary since the problem report dialog's URL isn't even set until after the _reportInfo is populated, // and we assume that nothing sends problemReport API requests except the problemReportDialog that this class loads. // ProblemDialog.tsx uses this endpoint to get the string to show at the top of the main dialog apiHandler.RegisterEndpointHandlerUsedByOthers("problemReport/reportHeadingHtml", (ApiRequest request) => { request.ReplyWithText(_reportInfo.HeadingHtml ?? ""); }, false); // ProblemDialog.tsx uses this endpoint to get the screenshot image. apiHandler.RegisterEndpointHandlerUsedByOthers("problemReport/screenshot", (ApiRequest request) => { // Wait until the screenshot is finished. // If not available within the time limit, just continue anyway (so we don't deadlock or anything) and hope for the best. bool isLockTaken = _takingScreenshotLock.Wait(millisecondsTimeout: 5000); if (_reportInfo?.ScreenshotTempFile == null) { request.Failed(); } else { request.ReplyWithImage(_reportInfo.ScreenshotTempFile.Path); } if (isLockTaken) { _takingScreenshotLock.Release(); } }, true); // ProblemDialog.tsx uses this endpoint to get the name of the book. apiHandler.RegisterEndpointHandlerUsedByOthers("problemReport/bookName", (ApiRequest request) => { request.ReplyWithText(_reportInfo.BookName ?? "??"); }, true); // ProblemDialog.tsx uses this endpoint to get the registered user's email address. apiHandler.RegisterEndpointHandlerUsedByOthers("problemReport/emailAddress", (ApiRequest request) => { request.ReplyWithText(_reportInfo.UserEmail); }, true); // PrivacyScreen.tsx uses this endpoint to show the user what info will be included in the report. apiHandler.RegisterEndpointHandlerUsedByOthers("problemReport/diagnosticInfo", (ApiRequest request) => { var userWantsToIncludeBook = request.RequiredParam("includeBook") == "true"; var userInput = request.RequiredParam("userInput"); var userEmail = request.RequiredParam("email"); request.ReplyWithText(GetDiagnosticInfo(userWantsToIncludeBook, userInput, userEmail)); }, true); // ProblemDialog.tsx uses this endpoint in its AttemptSubmit method; // it expects a response that it will use to show the issue link to the user. apiHandler.RegisterEndpointHandlerUsedByOthers("problemReport/submit", (ApiRequest request) => { var report = DynamicJson.Parse(request.RequiredPostJson()); string issueLink = SubmitToYouTrack(report.kind, report.userInput, report.email, report.includeBook, report.includeScreenshot, null); object linkToNewIssue = new { issueLink }; request.ReplyWithJson(linkToNewIssue); }, true); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { // This is just for storing the user preference of method // If we had a couple of these, we could just have a generic preferences api // that browser-side code could use. apiHandler.RegisterEndpointLegacy(kApiUrlPart + "method", request => { if (request.HttpMethod == HttpMethods.Get) { var method = Settings.Default.PublishAndroidMethod; if (!new string[] { "wifi", "usb", "file" }.Contains(method)) { method = "wifi"; } request.ReplyWithText(method); } else // post { Settings.Default.PublishAndroidMethod = request.RequiredPostString(); #if __MonoCS__ if (Settings.Default.PublishAndroidMethod == "usb") { _progress.MessageWithoutLocalizing("Sorry, this method is not available on Linux yet."); } #endif request.PostSucceeded(); } }, true); apiHandler.RegisterEndpointLegacy(kApiUrlPart + "backColor", request => { if (request.HttpMethod == HttpMethods.Get) { if (request.CurrentBook != _coverColorSourceBook) { _coverColorSourceBook = request.CurrentBook; ImageUtils.TryCssColorFromString(request.CurrentBook?.GetCoverColor() ?? "", out _thumbnailBackgroundColor); } request.ReplyWithText(ToCssColorString(_thumbnailBackgroundColor)); } else // post { // ignore invalid colors (very common while user is editing hex) Color newColor; var newColorAsString = request.RequiredPostString(); if (ImageUtils.TryCssColorFromString(newColorAsString, out newColor)) { _thumbnailBackgroundColor = newColor; request.CurrentBook.SetCoverColor(newColorAsString); } request.PostSucceeded(); } }, true); apiHandler.RegisterBooleanEndpointHandler(kApiUrlPart + "motionBookMode", readRequest => { // If the user has taken off all possible motion, force not having motion in the // Bloom Reader book. See https://issues.bloomlibrary.org/youtrack/issue/BL-7680. if (!readRequest.CurrentBook.HasMotionPages) { readRequest.CurrentBook.BookInfo.PublishSettings.BloomPub.Motion = false; } return(readRequest.CurrentBook.BookInfo.PublishSettings.BloomPub.Motion); }, (writeRequest, value) => { writeRequest.CurrentBook.BookInfo.PublishSettings.BloomPub.Motion = value; writeRequest.CurrentBook.BookInfo.SavePublishSettings(); _webSocketServer.SendEvent("publish", "motionChanged"); } , true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "updatePreview", request => { MakeBloompubPreview(request, false); }, false); apiHandler.RegisterEndpointLegacy(kApiUrlPart + "thumbnail", request => { var coverImage = request.CurrentBook.GetCoverImagePath(); if (coverImage == null) { request.Failed("no cover image"); } else { // We don't care as much about making it resized as making its background transparent. using (var thumbnail = TempFile.CreateAndGetPathButDontMakeTheFile()) { if (_thumbnailBackgroundColor == Color.Transparent) { ImageUtils.TryCssColorFromString(request.CurrentBook?.GetCoverColor(), out _thumbnailBackgroundColor); } RuntimeImageProcessor.GenerateEBookThumbnail(coverImage, thumbnail.Path, 256, 256, _thumbnailBackgroundColor); request.ReplyWithImage(thumbnail.Path); } } }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "usb/start", request => { #if !__MonoCS__ SetState("UsbStarted"); UpdatePreviewIfNeeded(request); _usbPublisher.Connect(request.CurrentBook, _thumbnailBackgroundColor, GetSettings()); #endif request.PostSucceeded(); }, true); apiHandler.RegisterEndpointHandler(kApiUrlPart + "usb/stop", request => { #if !__MonoCS__ _usbPublisher.Stop(disposing: false); SetState("stopped"); #endif request.PostSucceeded(); }, true); apiHandler.RegisterEndpointLegacy(kApiUrlPart + "wifi/start", request => { SetState("ServingOnWifi"); UpdatePreviewIfNeeded(request); _wifiPublisher.Start(request.CurrentBook, request.CurrentCollectionSettings, _thumbnailBackgroundColor, GetSettings()); request.PostSucceeded(); }, true); apiHandler.RegisterEndpointLegacy(kApiUrlPart + "wifi/stop", request => { _wifiPublisher.Stop(); SetState("stopped"); request.PostSucceeded(); }, true); apiHandler.RegisterEndpointLegacy(kApiUrlPart + "file/save", request => { UpdatePreviewIfNeeded(request); FilePublisher.Save(request.CurrentBook, _bookServer, _thumbnailBackgroundColor, _progress, GetSettings()); SetState("stopped"); request.PostSucceeded(); }, true); apiHandler.RegisterEndpointLegacy(kApiUrlPart + "file/bulkSaveBloomPubsParams", request => { request.ReplyWithJson(JsonConvert.SerializeObject(_collectionSettings.BulkPublishBloomPubSettings)); }, true); apiHandler.RegisterEndpointLegacy(kApiUrlPart + "file/bulkSaveBloomPubs", request => { // update what's in the collection so that we remember for next time _collectionSettings.BulkPublishBloomPubSettings = request.RequiredPostObject <BulkBloomPubPublishSettings>(); _collectionSettings.Save(); _bulkBloomPubCreator.PublishAllBooks(_collectionSettings.BulkPublishBloomPubSettings); SetState("stopped"); request.PostSucceeded(); }, true); apiHandler.RegisterEndpointLegacy(kApiUrlPart + "textToClipboard", request => { PortableClipboard.SetText(request.RequiredPostString()); request.PostSucceeded(); }, true); apiHandler.RegisterBooleanEndpointHandler(kApiUrlPart + "canHaveMotionMode", request => { return(request.CurrentBook.HasMotionPages); }, null, // no write action false, true); // we don't really know, just safe default apiHandler.RegisterBooleanEndpointHandler(kApiUrlPart + "canRotate", request => { return(request.CurrentBook.BookInfo.PublishSettings.BloomPub.Motion && request.CurrentBook.HasMotionPages); }, null, // no write action false, true); // we don't really know, just safe default apiHandler.RegisterBooleanEndpointHandler(kApiUrlPart + "defaultLandscape", request => { return(request.CurrentBook.GetLayout().SizeAndOrientation.IsLandScape); }, null, // no write action false, true); // we don't really know, just safe default apiHandler.RegisterEndpointLegacy(kApiUrlPart + "languagesInBook", request => { try { InitializeLanguagesInBook(request); Dictionary <string, InclusionSetting> textLangsToPublish = request.CurrentBook.BookInfo.PublishSettings.BloomPub.TextLangs; Dictionary <string, InclusionSetting> audioLangsToPublish = request.CurrentBook.BookInfo.PublishSettings.BloomPub.AudioLangs; var result = "[" + string.Join(",", _allLanguages.Select(kvp => { string langCode = kvp.Key; bool includeText = false; if (textLangsToPublish != null && textLangsToPublish.TryGetValue(langCode, out InclusionSetting includeTextSetting)) { includeText = includeTextSetting.IsIncluded(); } bool includeAudio = false; if (audioLangsToPublish != null && audioLangsToPublish.TryGetValue(langCode, out InclusionSetting includeAudioSetting)) { includeAudio = includeAudioSetting.IsIncluded(); } var value = new LanguagePublishInfo() { code = kvp.Key, name = request.CurrentBook.PrettyPrintLanguage(langCode), complete = kvp.Value, includeText = includeText, containsAnyAudio = _languagesWithAudio.Contains(langCode), includeAudio = includeAudio }; var json = JsonConvert.SerializeObject(value); return(json); })) + "]"; request.ReplyWithText(result); }
public void RegisterWithApiHandler(BloomApiHandler apiHandler) { apiHandler.RegisterEndpointHandler(kApiUrlPart + "names", HandleNamesRequest, false); apiHandler.RegisterEndpointHandler(kApiUrlPart + "metadata", HandleMetadataRequest, false); }