-
-
Notifications
You must be signed in to change notification settings - Fork 744
Additional APIs for WebContents #958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dae5211
e09ef35
90f5f5d
7eaf84a
ce8a86b
65db66b
c0e3a59
46d395a
e52bf69
7c39d28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,7 +123,7 @@ internal WebContents(int id) | |
| /// </summary> | ||
| public void OpenDevTools() | ||
| { | ||
| BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id); | ||
| BridgeConnector.Socket.Emit("webContents-openDevTools", Id); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -132,7 +132,41 @@ public void OpenDevTools() | |
| /// <param name="openDevToolsOptions"></param> | ||
| public void OpenDevTools(OpenDevToolsOptions openDevToolsOptions) | ||
| { | ||
| BridgeConnector.Socket.Emit("webContentsOpenDevTools", Id, openDevToolsOptions); | ||
| BridgeConnector.Socket.Emit("webContents-openDevTools", Id, openDevToolsOptions); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Toggles the devtools. | ||
| /// </summary> | ||
| public void ToggleDevTools() | ||
| { | ||
| BridgeConnector.Socket.Emit("webContents-toggleDevTools", Id); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Closes the devtools. | ||
| /// </summary> | ||
| public void CloseDevTools() | ||
| { | ||
| BridgeConnector.Socket.Emit("webContents-closeDevTools", Id); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns boolean - Whether the devtools is opened. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public bool IsDevToolsOpened() | ||
| { | ||
| return Task.Run(() => InvokeAsync<bool>()).Result; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns boolean - Whether the devtools view is focused. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public bool IsDevToolsFocused() | ||
| { | ||
| return Task.Run(() => InvokeAsync<bool>()).Result; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -280,4 +314,151 @@ public void InsertCSS(bool isBrowserWindow, string path) | |
| { | ||
| BridgeConnector.Socket.Emit("webContents-insertCSS", Id, isBrowserWindow, path); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A number property that determines the zoom level for this web contents. | ||
| ///The original size is 0 and each increment above or below represents zooming 20% larger or smaller to default limits of 300% and 50% of original size, respectively. | ||
| ///The formula for this is scale := 1.2 ^ level. | ||
| /// </summary> | ||
| public int ZoomLevel | ||
| { | ||
| get | ||
| { | ||
| return Task.Run(() => this.InvokeAsync<int>()).Result; | ||
| } | ||
| set | ||
| { | ||
| BridgeConnector.Socket.Emit("webContents-zoomLevel-set", Id, value); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A number property that determines the zoom factor for this web contents. | ||
| ///The zoom factor is the zoom percent divided by 100, so 300% = 3.0. | ||
| /// </summary> | ||
| public double ZoomFactor | ||
| { | ||
| get | ||
| { | ||
| return Task.Run(() => this.InvokeAsync<double>()).Result; | ||
| } | ||
| set | ||
| { | ||
| BridgeConnector.Socket.Emit("webContents-zoomFactor-set", Id, value); | ||
| } | ||
| } | ||
|
Comment on lines
+323
to
+349
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. => async! |
||
|
|
||
| /// <summary> | ||
| /// Returns number - The current zoom factor. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public Task<double> GetZoomFactorAsync() => InvokeAsync<double>(); | ||
|
|
||
| /// <summary> | ||
| /// Changes the zoom factor to the specified factor. | ||
| /// Zoom factor is zoom percent divided by 100, so 300% = 3.0. | ||
| /// The factor must be greater than 0.0. | ||
| /// </summary> | ||
| /// <param name="factor"></param> | ||
| public void SetZoomFactor(double factor) | ||
| { | ||
| BridgeConnector.Socket.Emit("webContents-setZoomFactor", Id, factor); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Returns number - The current zoom level. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public Task<int> GetZoomLevelAsync() => InvokeAsync<int>(); | ||
|
|
||
| /// <summary> | ||
| /// Changes the zoom level to the specified level. | ||
| /// The original size is 0 and each increment above or below represents zooming 20% larger or smaller to default limits of 300% and 50% of original size, respectively. | ||
| /// </summary> | ||
| /// <param name="level"></param> | ||
| public void SetZoomLevel(int level) | ||
| { | ||
| BridgeConnector.Socket.Emit("webContents-setZoomLevel", Id, level); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sets the maximum and minimum pinch-to-zoom level. | ||
| /// </summary> | ||
| /// <param name="minimumLevel"></param> | ||
| /// <param name="maximumLevel"></param> | ||
| public Task SetVisualZoomLevelLimitsAsync(int minimumLevel, int maximumLevel) | ||
| { | ||
| var tcs = new TaskCompletionSource(); | ||
|
|
||
| BridgeConnector.Socket.Once("webContents-setVisualZoomLevelLimits-completed", tcs.SetResult); | ||
| BridgeConnector.Socket.Emit("webContents-setVisualZoomLevelLimits", Id, minimumLevel, maximumLevel); | ||
|
|
||
| return tcs.Task; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A boolean property that determines whether this page is muted. | ||
| /// </summary> | ||
| public bool AudioMuted | ||
| { | ||
| get | ||
| { | ||
| return Task.Run(() => this.InvokeAsync<bool>()).Result; | ||
| } | ||
| set | ||
| { | ||
| BridgeConnector.Socket.Emit("webContents-audioMuted-set", Id, value); | ||
| } | ||
| } | ||
|
Comment on lines
+402
to
+412
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. => async |
||
|
|
||
| /// <summary> | ||
| /// Returns boolean - Whether this page has been muted. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public Task<bool> IsAudioMutedAsync() => InvokeAsync<bool>(); | ||
|
|
||
| /// <summary> | ||
| /// Returns boolean - Whether audio is currently playing. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public Task<bool> IsCurrentlyAudibleAsync() => InvokeAsync<bool>(); | ||
|
|
||
| /// <summary> | ||
| /// Mute the audio on the current web page. | ||
| /// </summary> | ||
| /// <param name="muted"></param> | ||
| public void SetAudioMuted(bool muted) | ||
| { | ||
| BridgeConnector.Socket.Emit("webContents-setAudioMuted", Id, muted); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A string property that determines the user agent for this web page. | ||
| /// </summary> | ||
| public string UserAgent | ||
| { | ||
| get | ||
| { | ||
| return Task.Run(() => this.InvokeAsync<string>()).Result; | ||
| } | ||
| set | ||
| { | ||
| BridgeConnector.Socket.Emit("webContents-userAgent-set", Id, value); | ||
| } | ||
| } | ||
|
Comment on lines
+438
to
+448
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. => async |
||
|
|
||
| /// <summary> | ||
| /// Returns string - The user agent for this web page. | ||
| /// </summary> | ||
| /// <returns></returns> | ||
| public Task<string> GetUserAgentAsync() => InvokeAsync<string>(); | ||
|
|
||
| /// <summary> | ||
| /// Overrides the user agent for this web page. | ||
| /// </summary> | ||
| /// <param name="userAgent"></param> | ||
| public void SetUserAgent(string userAgent) | ||
| { | ||
| BridgeConnector.Socket.Emit("webContents-setUserAgent", Id, userAgent); | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These properties should be async. It could deadlock like this.