2017-10-03 03:28:56 +02:00
using ElectronNET.API.Entities ;
using Newtonsoft.Json ;
using Newtonsoft.Json.Linq ;
using Newtonsoft.Json.Serialization ;
using System ;
2017-11-10 01:48:06 +01:00
using System.Threading ;
2017-10-12 02:24:27 +02:00
using System.Threading.Tasks ;
2017-10-03 03:28:56 +02:00
namespace ElectronNET.API
{
2017-10-24 21:43:27 +02:00
/// <summary>
/// Control your application's event lifecycle.
/// </summary>
2017-10-14 17:58:16 +02:00
public sealed class App
2017-10-03 03:28:56 +02:00
{
2017-10-14 19:57:49 +02:00
/// <summary>
/// Emitted when all windows have been closed.
///
/// If you do not subscribe to this event and all windows are closed,
/// the default behavior is to quit the app; however, if you subscribe,
/// you control whether the app quits or not.If the user pressed Cmd + Q,
/// or the developer called app.quit(), Electron will first try to close
/// all the windows and then emit the will-quit event, and in this case the
/// window-all-closed event would not be emitted.
/// </summary>
public event Action WindowAllClosed
{
add
{
if ( _windowAllClosed = = null )
{
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . On ( "app-window-all-closed" + GetHashCode ( ) , ( ) = >
2017-10-14 19:57:49 +02:00
{
2017-11-10 01:48:06 +01:00
if ( ! Electron . WindowManager . IsQuitOnWindowAllClosed )
{
_windowAllClosed ( ) ;
}
2017-10-14 19:57:49 +02:00
} ) ;
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . Emit ( "register-app-window-all-closed-event" , GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
_windowAllClosed + = value ;
}
remove
{
_windowAllClosed - = value ;
2017-10-25 21:28:43 +02:00
if ( _windowAllClosed = = null )
BridgeConnector . Socket . Off ( "app-window-all-closed" + GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
}
private event Action _windowAllClosed ;
/// <summary>
/// Emitted before the application starts closing its windows.
///
/// Note: If application quit was initiated by autoUpdater.quitAndInstall() then before-quit is emitted after
/// emitting close event on all windows and closing them.
/// </summary>
2017-11-10 03:11:13 +01:00
public event Func < QuitEventArgs , Task > BeforeQuit
2017-10-14 19:57:49 +02:00
{
add
{
if ( _beforeQuit = = null )
{
2017-11-10 01:48:06 +01:00
BridgeConnector . Socket . On ( "app-before-quit" + GetHashCode ( ) , async ( ) = >
2017-10-14 19:57:49 +02:00
{
2017-11-10 03:11:13 +01:00
await _beforeQuit ( new QuitEventArgs ( ) ) ;
2017-11-10 01:48:06 +01:00
2017-11-10 03:11:13 +01:00
if ( _preventQuit )
2017-11-10 01:48:06 +01:00
{
2017-11-10 03:11:13 +01:00
_preventQuit = false ;
2017-11-10 01:48:06 +01:00
}
2017-11-10 03:11:13 +01:00
else
2017-11-10 01:48:06 +01:00
{
2017-11-10 03:11:13 +01:00
if ( _willQuit = = null & & _quitting = = null )
2017-11-10 01:48:06 +01:00
{
Exit ( ) ;
2017-11-10 03:11:13 +01:00
}
else if ( _willQuit ! = null )
{
await _willQuit ( new QuitEventArgs ( ) ) ;
if ( _preventQuit )
{
_preventQuit = false ;
}
else
{
if ( _quitting = = null )
{
Exit ( ) ;
}
else
{
await _quitting ( ) ;
Exit ( ) ;
}
}
}
else if ( _quitting ! = null )
2017-11-10 01:48:06 +01:00
{
await _quitting ( ) ;
Exit ( ) ;
}
}
2017-10-14 19:57:49 +02:00
} ) ;
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . Emit ( "register-app-before-quit-event" , GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
_beforeQuit + = value ;
}
remove
{
_beforeQuit - = value ;
2017-10-25 21:28:43 +02:00
if ( _beforeQuit = = null )
BridgeConnector . Socket . Off ( "app-before-quit" + GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
}
2017-11-10 03:11:13 +01:00
private event Func < QuitEventArgs , Task > _beforeQuit ;
2017-10-14 19:57:49 +02:00
/// <summary>
/// Emitted when all windows have been closed and the application will quit.
///
/// See the description of the window-all-closed event for the differences between the will-quit and
/// window-all-closed events.
/// </summary>
2017-11-10 03:11:13 +01:00
public event Func < QuitEventArgs , Task > WillQuit
2017-10-14 19:57:49 +02:00
{
add
{
if ( _willQuit = = null )
{
2017-11-10 01:48:06 +01:00
BridgeConnector . Socket . On ( "app-will-quit" + GetHashCode ( ) , async ( ) = >
2017-10-14 19:57:49 +02:00
{
2017-11-10 03:11:13 +01:00
await _willQuit ( new QuitEventArgs ( ) ) ;
2017-11-10 01:48:06 +01:00
2017-11-10 03:11:13 +01:00
if ( _preventQuit )
2017-11-10 01:48:06 +01:00
{
2017-11-10 03:11:13 +01:00
_preventQuit = false ;
2017-11-10 01:48:06 +01:00
}
else
{
2017-11-10 03:11:13 +01:00
if ( _quitting = = null )
{
Exit ( ) ;
}
else
{
await _quitting ( ) ;
Exit ( ) ;
}
2017-11-10 01:48:06 +01:00
}
2017-10-14 19:57:49 +02:00
} ) ;
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . Emit ( "register-app-will-quit-event" , GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
_willQuit + = value ;
}
remove
{
_willQuit - = value ;
2017-10-25 21:28:43 +02:00
if ( _willQuit = = null )
BridgeConnector . Socket . Off ( "app-will-quit" + GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
}
2017-11-10 03:11:13 +01:00
private event Func < QuitEventArgs , Task > _willQuit ;
2017-10-14 19:57:49 +02:00
/// <summary>
/// Emitted when the application is quitting.
/// </summary>
2017-11-10 01:48:06 +01:00
public event Func < Task > Quitting
2017-10-14 19:57:49 +02:00
{
add
{
if ( _quitting = = null )
{
2017-11-10 01:48:06 +01:00
BridgeConnector . Socket . On ( "app-will-quit" + GetHashCode ( ) + "quitting" , async ( ) = >
2017-10-14 19:57:49 +02:00
{
2017-11-10 01:48:06 +01:00
if ( _willQuit = = null )
{
await _quitting ( ) ;
Exit ( ) ;
}
2017-10-14 19:57:49 +02:00
} ) ;
2017-11-10 01:48:06 +01:00
BridgeConnector . Socket . Emit ( "register-app-will-quit-event" , GetHashCode ( ) + "quitting" ) ;
2017-10-14 19:57:49 +02:00
}
_quitting + = value ;
}
remove
{
_quitting - = value ;
2017-10-25 21:28:43 +02:00
if ( _quitting = = null )
2017-11-10 01:48:06 +01:00
BridgeConnector . Socket . Off ( "app-will-quit" + GetHashCode ( ) + "quitting" ) ;
2017-10-14 19:57:49 +02:00
}
}
2017-11-10 01:48:06 +01:00
private event Func < Task > _quitting ;
2017-10-14 19:57:49 +02:00
/// <summary>
/// Emitted when a BrowserWindow gets blurred.
/// </summary>
public event Action BrowserWindowBlur
{
add
{
if ( _browserWindowBlur = = null )
{
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . On ( "app-browser-window-blur" + GetHashCode ( ) , ( ) = >
2017-10-14 19:57:49 +02:00
{
_browserWindowBlur ( ) ;
} ) ;
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . Emit ( "register-app-browser-window-blur-event" , GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
_browserWindowBlur + = value ;
}
remove
{
_browserWindowBlur - = value ;
2017-10-25 21:28:43 +02:00
if ( _browserWindowBlur = = null )
BridgeConnector . Socket . Off ( "app-browser-window-blur" + GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
}
private event Action _browserWindowBlur ;
/// <summary>
/// Emitted when a BrowserWindow gets focused.
/// </summary>
public event Action BrowserWindowFocus
{
add
{
if ( _browserWindowFocus = = null )
{
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . On ( "app-browser-window-focus" + GetHashCode ( ) , ( ) = >
2017-10-14 19:57:49 +02:00
{
_browserWindowFocus ( ) ;
} ) ;
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . Emit ( "register-app-browser-window-focus-event" , GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
_browserWindowFocus + = value ;
}
remove
{
_browserWindowFocus - = value ;
2017-10-25 21:28:43 +02:00
if ( _browserWindowFocus = = null )
BridgeConnector . Socket . Off ( "app-browser-window-focus" + GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
}
private event Action _browserWindowFocus ;
/// <summary>
/// Emitted when a new BrowserWindow is created.
/// </summary>
public event Action BrowserWindowCreated
{
add
{
if ( _browserWindowCreated = = null )
{
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . On ( "app-browser-window-created" + GetHashCode ( ) , ( ) = >
2017-10-14 19:57:49 +02:00
{
_browserWindowCreated ( ) ;
} ) ;
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . Emit ( "register-app-browser-window-created-event" , GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
_browserWindowCreated + = value ;
}
remove
{
_browserWindowCreated - = value ;
2017-10-25 21:28:43 +02:00
if ( _browserWindowCreated = = null )
BridgeConnector . Socket . Off ( "app-browser-window-created" + GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
}
private event Action _browserWindowCreated ;
/// <summary>
/// Emitted when a new webContents is created.
/// </summary>
public event Action WebContentsCreated
{
add
{
if ( _webContentsCreated = = null )
{
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . On ( "app-web-contents-created" + GetHashCode ( ) , ( ) = >
2017-10-14 19:57:49 +02:00
{
_webContentsCreated ( ) ;
} ) ;
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . Emit ( "register-app-web-contents-created-event" , GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
_webContentsCreated + = value ;
}
remove
{
_webContentsCreated - = value ;
2017-10-25 21:28:43 +02:00
if ( _webContentsCreated = = null )
BridgeConnector . Socket . Off ( "app-web-contents-created" + GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
}
private event Action _webContentsCreated ;
/// <summary>
/// Emitted when Chrome’ s accessibility support changes.
/// This event fires when assistive technologies, such as screen readers, are enabled or disabled.
/// See https://www.chromium.org/developers/design-documents/accessibility for more details.
/// </summary>
public event Action < bool > AccessibilitySupportChanged
{
add
{
if ( _accessibilitySupportChanged = = null )
{
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . On ( "app-accessibility-support-changed" + GetHashCode ( ) , ( state ) = >
2017-10-14 19:57:49 +02:00
{
_accessibilitySupportChanged ( ( bool ) state ) ;
} ) ;
2017-10-25 21:28:43 +02:00
BridgeConnector . Socket . Emit ( "register-app-accessibility-support-changed-event" , GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
_accessibilitySupportChanged + = value ;
}
remove
{
_accessibilitySupportChanged - = value ;
2017-10-25 21:28:43 +02:00
if ( _accessibilitySupportChanged = = null )
BridgeConnector . Socket . Off ( "app-accessibility-support-changed" + GetHashCode ( ) ) ;
2017-10-14 19:57:49 +02:00
}
}
private event Action < bool > _accessibilitySupportChanged ;
2017-10-12 02:24:27 +02:00
2019-11-30 01:30:22 +01:00
internal App ( )
{
CommandLine = new CommandLine ( ) ;
}
2017-10-03 03:28:56 +02:00
2017-10-15 06:03:48 +02:00
internal static App Instance
2017-10-03 03:28:56 +02:00
{
2017-10-14 17:58:16 +02:00
get
2017-10-03 03:28:56 +02:00
{
2017-10-14 17:58:16 +02:00
if ( _app = = null )
{
2017-11-04 00:16:14 +01:00
lock ( _syncRoot )
{
if ( _app = = null )
{
_app = new App ( ) ;
}
}
2017-10-14 17:58:16 +02:00
}
2017-10-03 03:28:56 +02:00
2017-10-14 17:58:16 +02:00
return _app ;
}
}
2017-10-03 03:28:56 +02:00
2017-10-14 19:57:49 +02:00
private static App _app ;
2019-05-18 02:00:56 +02:00
private static object _syncRoot = new object ( ) ;
2017-10-14 19:57:49 +02:00
2017-10-14 17:58:16 +02:00
private JsonSerializer _jsonSerializer = new JsonSerializer ( )
{
ContractResolver = new CamelCasePropertyNamesContractResolver ( )
} ;
2017-10-03 03:28:56 +02:00
2017-10-14 14:41:11 +02:00
/// <summary>
/// Try to close all windows. The before-quit event will be emitted first. If all
/// windows are successfully closed, the will-quit event will be emitted and by
/// default the application will terminate. This method guarantees that all
/// beforeunload and unload event handlers are correctly executed. It is possible
/// that a window cancels the quitting by returning false in the beforeunload event
/// handler.
/// </summary>
2017-10-14 17:58:16 +02:00
public void Quit ( )
2017-10-12 02:24:27 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appQuit" ) ;
2017-10-12 02:24:27 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// All windows will be closed immediately without asking user and
/// the before-quit and will-quit events will not be emitted.
/// </summary>
/// <param name="exitCode">Exits immediately with exitCode. exitCode defaults to 0.</param>
2017-10-14 17:58:16 +02:00
public void Exit ( int exitCode = 0 )
2017-10-12 02:24:27 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appExit" , exitCode ) ;
2017-10-12 02:24:27 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Relaunches the app when current instance exits. By default the new instance will
/// use the same working directory and command line arguments with current instance.
/// When args is specified, the args will be passed as command line arguments
/// instead. When execPath is specified, the execPath will be executed for relaunch
/// instead of current app. Note that this method does not quit the app when
/// executed, you have to call app.quit or app.exit after calling app.relaunch to
/// make the app restart. When app.relaunch is called for multiple times, multiple
/// instances will be started after current instance exited.
/// </summary>
2017-10-14 17:58:16 +02:00
public void Relaunch ( )
2017-10-12 02:24:27 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appRelaunch" ) ;
2017-10-12 02:24:27 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Relaunches the app when current instance exits. By default the new instance will
/// use the same working directory and command line arguments with current instance.
/// When args is specified, the args will be passed as command line arguments
/// instead. When execPath is specified, the execPath will be executed for relaunch
/// instead of current app. Note that this method does not quit the app when
/// executed, you have to call app.quit or app.exit after calling app.relaunch to
/// make the app restart. When app.relaunch is called for multiple times, multiple
/// instances will be started after current instance exited.
/// </summary>
/// <param name="relaunchOptions"></param>
2017-10-14 17:58:16 +02:00
public void Relaunch ( RelaunchOptions relaunchOptions )
2017-10-12 02:24:27 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appRelaunch" , JObject . FromObject ( relaunchOptions , _jsonSerializer ) ) ;
2017-10-12 02:24:27 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// On Linux, focuses on the first visible window. On macOS, makes the application
/// the active app.On Windows, focuses on the application's first window.
/// </summary>
2017-10-14 17:58:16 +02:00
public void Focus ( )
2017-10-12 02:24:27 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appFocus" ) ;
2017-10-12 02:24:27 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Hides all application windows without minimizing them.
/// </summary>
2017-10-14 17:58:16 +02:00
public void Hide ( )
2017-10-12 02:24:27 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appHide" ) ;
2017-10-12 02:24:27 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Shows application windows after they were hidden. Does not automatically focus them.
/// </summary>
2017-10-14 17:58:16 +02:00
public void Show ( )
2017-10-12 02:24:27 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appShow" ) ;
2017-10-12 02:24:27 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// The current application directory.
/// </summary>
/// <returns></returns>
2017-11-13 20:47:31 +01:00
public async Task < string > GetAppPathAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-12 02:24:27 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-12 02:24:27 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < string > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-12 02:24:27 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appGetAppPathCompleted" , ( path ) = >
{
BridgeConnector . Socket . Off ( "appGetAppPathCompleted" ) ;
taskCompletionSource . SetResult ( path . ToString ( ) ) ;
} ) ;
2017-10-12 02:24:27 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appGetAppPath" ) ;
2017-10-12 02:24:27 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-12 02:24:27 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// You can request the following paths by the name.
/// </summary>
/// <returns>A path to a special directory or file associated with name.</returns>
2017-11-13 20:47:31 +01:00
public async Task < string > GetPathAsync ( PathName pathName , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-12 02:24:27 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-12 02:24:27 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < string > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
{
BridgeConnector . Socket . On ( "appGetPathCompleted" , ( path ) = >
{
BridgeConnector . Socket . Off ( "appGetPathCompleted" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
taskCompletionSource . SetResult ( path . ToString ( ) ) ;
} ) ;
2017-10-12 02:24:27 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appGetPath" , pathName . ToString ( ) ) ;
2017-10-12 02:24:27 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-12 02:24:27 +02:00
}
2017-10-14 00:06:58 +02:00
2017-10-14 14:41:11 +02:00
/// <summary>
/// Overrides the path to a special directory or file associated with name. If the
/// path specifies a directory that does not exist, the directory will be created by
/// this method.On failure an Error is thrown.You can only override paths of a
/// name defined in app.getPath. By default, web pages' cookies and caches will be
/// stored under the userData directory.If you want to change this location, you
/// have to override the userData path before the ready event of the app module is emitted.
/// </summary>
2017-10-14 17:58:16 +02:00
public void SetPath ( string name , string path )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appSetPath" , name , path ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// The version of the loaded application.
/// If no version is found in the application’ s package.json file,
/// the version of the current bundle or executable is returned.
/// </summary>
/// <returns></returns>
2017-11-13 20:47:31 +01:00
public async Task < string > GetVersionAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < string > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appGetVersionCompleted" , ( version ) = >
{
BridgeConnector . Socket . Off ( "appGetVersionCompleted" ) ;
taskCompletionSource . SetResult ( version . ToString ( ) ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appGetVersion" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Usually the name field of package.json is a short lowercased name, according to
/// the npm modules spec. You should usually also specify a productName field, which
/// is your application's full capitalized name, and which will be preferred over
/// name by Electron.
/// </summary>
/// <returns>The current application’ s name, which is the name in the application’ s package.json file.</returns>
2017-11-13 20:47:31 +01:00
public async Task < string > GetNameAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < string > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appGetNameCompleted" , ( name ) = >
{
BridgeConnector . Socket . Off ( "appGetNameCompleted" ) ;
taskCompletionSource . SetResult ( name . ToString ( ) ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appGetName" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Overrides the current application's name.
/// </summary>
/// <param name="name">Application's name</param>
2017-10-14 17:58:16 +02:00
public void SetName ( string name )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appSetName" , name ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// The current application locale.
/// Note: When distributing your packaged app, you have to also ship the locales
/// folder.Note: On Windows you have to call it after the ready events gets emitted.
/// </summary>
/// <returns></returns>
2017-11-13 20:47:31 +01:00
public async Task < string > GetLocaleAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < string > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appGetLocaleCompleted" , ( local ) = >
{
BridgeConnector . Socket . Off ( "appGetLocaleCompleted" ) ;
taskCompletionSource . SetResult ( local . ToString ( ) ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appGetLocale" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Adds path to the recent documents list. This list is managed by the OS. On
/// Windows you can visit the list from the task bar, and on macOS you can visit it
/// from dock menu.
/// </summary>
2017-10-14 17:58:16 +02:00
public void AddRecentDocument ( string path )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appAddRecentDocument" , path ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Clears the recent documents list.
/// </summary>
2017-10-14 17:58:16 +02:00
public void ClearRecentDocuments ( )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appClearRecentDocuments" ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// This method sets the current executable as the default handler for a protocol
/// (aka URI scheme). It allows you to integrate your app deeper into the operating
/// system.Once registered, all links with your-protocol:// will be opened with the
/// current executable. The whole link, including protocol, will be passed to your
/// application as a parameter. On Windows you can provide optional parameters path,
/// the path to your executable, and args, an array of arguments to be passed to
/// your executable when it launches.Note: On macOS, you can only register
/// protocols that have been added to your app's info.plist, which can not be
/// modified at runtime.You can however change the file with a simple text editor
/// or script during build time. Please refer to Apple's documentation for details.
/// The API uses the Windows Registry and LSSetDefaultHandlerForURLScheme
/// internally.
/// </summary>
/// <param name="protocol">The name of your protocol, without ://.
/// If you want your app to handle electron:// links,
/// call this method with electron as the parameter.</param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken">The cancellation token.</param>
2017-10-14 14:41:11 +02:00
/// <returns>Whether the call succeeded.</returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > SetAsDefaultProtocolClientAsync ( string protocol , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appSetAsDefaultProtocolClientCompleted" , ( success ) = >
{
BridgeConnector . Socket . Off ( "appSetAsDefaultProtocolClientCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) success ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appSetAsDefaultProtocolClient" , protocol ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// This method sets the current executable as the default handler for a protocol
/// (aka URI scheme). It allows you to integrate your app deeper into the operating
/// system.Once registered, all links with your-protocol:// will be opened with the
/// current executable. The whole link, including protocol, will be passed to your
/// application as a parameter. On Windows you can provide optional parameters path,
/// the path to your executable, and args, an array of arguments to be passed to
/// your executable when it launches.Note: On macOS, you can only register
/// protocols that have been added to your app's info.plist, which can not be
/// modified at runtime.You can however change the file with a simple text editor
/// or script during build time. Please refer to Apple's documentation for details.
/// The API uses the Windows Registry and LSSetDefaultHandlerForURLScheme
/// internally.
/// </summary>
/// <param name="protocol">The name of your protocol, without ://.
/// If you want your app to handle electron:// links,
/// call this method with electron as the parameter.</param>
/// <param name="path">Defaults to process.execPath</param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken">The cancellation token.</param>
2017-10-14 14:41:11 +02:00
/// <returns>Whether the call succeeded.</returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > SetAsDefaultProtocolClientAsync ( string protocol , string path , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appSetAsDefaultProtocolClientCompleted" , ( success ) = >
{
BridgeConnector . Socket . Off ( "appSetAsDefaultProtocolClientCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) success ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appSetAsDefaultProtocolClient" , protocol , path ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// This method sets the current executable as the default handler for a protocol
/// (aka URI scheme). It allows you to integrate your app deeper into the operating
/// system.Once registered, all links with your-protocol:// will be opened with the
/// current executable. The whole link, including protocol, will be passed to your
/// application as a parameter. On Windows you can provide optional parameters path,
/// the path to your executable, and args, an array of arguments to be passed to
/// your executable when it launches.Note: On macOS, you can only register
/// protocols that have been added to your app's info.plist, which can not be
/// modified at runtime.You can however change the file with a simple text editor
/// or script during build time. Please refer to Apple's documentation for details.
/// The API uses the Windows Registry and LSSetDefaultHandlerForURLScheme
/// internally.
/// </summary>
/// <param name="protocol">The name of your protocol, without ://.
/// If you want your app to handle electron:// links,
/// call this method with electron as the parameter.</param>
/// <param name="path">Defaults to process.execPath</param>
/// <param name="args">Defaults to an empty array</param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken">The cancellation token.</param>
2017-10-14 14:41:11 +02:00
/// <returns>Whether the call succeeded.</returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > SetAsDefaultProtocolClientAsync ( string protocol , string path , string [ ] args , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appSetAsDefaultProtocolClientCompleted" , ( success ) = >
{
BridgeConnector . Socket . Off ( "appSetAsDefaultProtocolClientCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) success ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appSetAsDefaultProtocolClient" , protocol , path , args ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// This method checks if the current executable as the default handler for a
/// protocol(aka URI scheme). If so, it will remove the app as the default handler.
/// </summary>
/// <param name="protocol">The name of your protocol, without ://.</param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken">The cancellation token.</param>
2017-10-14 14:41:11 +02:00
/// <returns>Whether the call succeeded.</returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > RemoveAsDefaultProtocolClientAsync ( string protocol , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appRemoveAsDefaultProtocolClientCompleted" , ( success ) = >
{
BridgeConnector . Socket . Off ( "appRemoveAsDefaultProtocolClientCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) success ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appRemoveAsDefaultProtocolClient" , protocol ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// This method checks if the current executable as the default handler for a
/// protocol(aka URI scheme). If so, it will remove the app as the default handler.
/// </summary>
/// <param name="protocol">The name of your protocol, without ://.</param>
/// <param name="path">Defaults to process.execPath.</param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken">The cancellation token.</param>
2017-10-14 14:41:11 +02:00
/// <returns>Whether the call succeeded.</returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > RemoveAsDefaultProtocolClientAsync ( string protocol , string path , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appRemoveAsDefaultProtocolClientCompleted" , ( success ) = >
{
BridgeConnector . Socket . Off ( "appRemoveAsDefaultProtocolClientCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) success ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appRemoveAsDefaultProtocolClient" , protocol , path ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// This method checks if the current executable as the default handler for a
/// protocol(aka URI scheme). If so, it will remove the app as the default handler.
/// </summary>
/// <param name="protocol">The name of your protocol, without ://.</param>
/// <param name="path">Defaults to process.execPath.</param>
/// <param name="args">Defaults to an empty array.</param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken">The cancellation token.</param>
2017-10-14 14:41:11 +02:00
/// <returns>Whether the call succeeded.</returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > RemoveAsDefaultProtocolClientAsync ( string protocol , string path , string [ ] args , CancellationToken cancellationToken = default ( CancellationToken ) )
{
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appRemoveAsDefaultProtocolClientCompleted" , ( success ) = >
{
BridgeConnector . Socket . Off ( "appRemoveAsDefaultProtocolClientCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) success ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appRemoveAsDefaultProtocolClient" , protocol , path , args ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// This method checks if the current executable is the default handler for a
/// protocol(aka URI scheme). If so, it will return true. Otherwise, it will return
/// false. Note: On macOS, you can use this method to check if the app has been
/// registered as the default protocol handler for a protocol.You can also verify
/// this by checking ~/Library/Preferences/com.apple.LaunchServices.plist on the
/// macOS machine.Please refer to Apple's documentation for details. The API uses
/// the Windows Registry and LSCopyDefaultHandlerForURLScheme internally.
/// </summary>
/// <param name="protocol">The name of your protocol, without ://.</param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken">The cancellation token.</param>
2017-10-14 14:41:11 +02:00
/// <returns>Returns Boolean</returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > IsDefaultProtocolClientAsync ( string protocol , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appIsDefaultProtocolClientCompleted" , ( success ) = >
{
BridgeConnector . Socket . Off ( "appIsDefaultProtocolClientCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) success ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appIsDefaultProtocolClient" , protocol ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// This method checks if the current executable is the default handler for a
/// protocol(aka URI scheme). If so, it will return true. Otherwise, it will return
/// false. Note: On macOS, you can use this method to check if the app has been
/// registered as the default protocol handler for a protocol.You can also verify
/// this by checking ~/Library/Preferences/com.apple.LaunchServices.plist on the
/// macOS machine.Please refer to Apple's documentation for details. The API uses
/// the Windows Registry and LSCopyDefaultHandlerForURLScheme internally.
/// </summary>
/// <param name="protocol">The name of your protocol, without ://.</param>
/// <param name="path">Defaults to process.execPath.</param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken">The cancellation token.</param>
2017-10-14 14:41:11 +02:00
/// <returns>Returns Boolean</returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > IsDefaultProtocolClientAsync ( string protocol , string path , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appIsDefaultProtocolClientCompleted" , ( success ) = >
{
BridgeConnector . Socket . Off ( "appIsDefaultProtocolClientCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) success ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appIsDefaultProtocolClient" , protocol , path ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// This method checks if the current executable is the default handler for a
/// protocol(aka URI scheme). If so, it will return true. Otherwise, it will return
/// false. Note: On macOS, you can use this method to check if the app has been
/// registered as the default protocol handler for a protocol.You can also verify
/// this by checking ~/Library/Preferences/com.apple.LaunchServices.plist on the
/// macOS machine.Please refer to Apple's documentation for details. The API uses
/// the Windows Registry and LSCopyDefaultHandlerForURLScheme internally.
/// </summary>
/// <param name="protocol">The name of your protocol, without ://.</param>
/// <param name="path">Defaults to process.execPath.</param>
/// <param name="args">Defaults to an empty array.</param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken">The cancellation token.</param>
2017-10-14 14:41:11 +02:00
/// <returns>Returns Boolean</returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > IsDefaultProtocolClientAsync ( string protocol , string path , string [ ] args , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appIsDefaultProtocolClientCompleted" , ( success ) = >
{
BridgeConnector . Socket . Off ( "appIsDefaultProtocolClientCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) success ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appIsDefaultProtocolClient" , protocol , path , args ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Adds tasks to the Tasks category of the JumpList on Windows. tasks is an array
/// of Task objects.Note: If you'd like to customize the Jump List even more use
/// app.setJumpList(categories) instead.
/// </summary>
/// <param name="userTasks">Array of Task objects.</param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken">The cancellation token.</param>
2017-10-14 14:41:11 +02:00
/// <returns>Whether the call succeeded.</returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > SetUserTasksAsync ( UserTask [ ] userTasks , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appSetUserTasksCompleted" , ( success ) = >
{
BridgeConnector . Socket . Off ( "appSetUserTasksCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) success ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appSetUserTasks" , JObject . FromObject ( userTasks , _jsonSerializer ) ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Jump List settings for the application.
/// </summary>
/// <returns></returns>
2017-11-13 20:47:31 +01:00
public async Task < JumpListSettings > GetJumpListSettingsAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < JumpListSettings > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appGetJumpListSettingsCompleted" , ( jumplistSettings ) = >
{
BridgeConnector . Socket . Off ( "appGetJumpListSettingsCompleted" ) ;
taskCompletionSource . SetResult ( JObject . Parse ( jumplistSettings . ToString ( ) ) . ToObject < JumpListSettings > ( ) ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appGetJumpListSettings" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Sets or removes a custom Jump List for the application, and returns one of the
/// following strings: If categories is null the previously set custom Jump List(if
/// any) will be replaced by the standard Jump List for the app(managed by
/// Windows). Note: If a JumpListCategory object has neither the type nor the name
/// property set then its type is assumed to be tasks.If the name property is set
/// but the type property is omitted then the type is assumed to be custom. Note:
/// Users can remove items from custom categories, and Windows will not allow a
/// removed item to be added back into a custom category until after the next
/// successful call to app.setJumpList(categories). Any attempt to re-add a removed
/// item to a custom category earlier than that will result in the entire custom
/// category being omitted from the Jump List. The list of removed items can be
/// obtained using app.getJumpListSettings().
/// </summary>
/// <param name="jumpListCategories"></param>
2017-10-14 17:58:16 +02:00
public void SetJumpList ( JumpListCategory [ ] jumpListCategories )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appSetJumpList" , JObject . FromObject ( jumpListCategories , _jsonSerializer ) ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// This method makes your application a Single Instance Application - instead of
/// allowing multiple instances of your app to run, this will ensure that only a
/// single instance of your app is running, and other instances signal this instance
/// and exit.callback will be called by the first instance with callback(argv,
/// workingDirectory) when a second instance has been executed.argv is an Array of
/// the second instance's command line arguments, and workingDirectory is its
/// current working directory.Usually applications respond to this by making their
/// primary window focused and non-minimized.The callback is guaranteed to be
/// executed after the ready event of app gets emitted.This method returns false if
/// your process is the primary instance of the application and your app should
/// continue loading.And returns true if your process has sent its parameters to
/// another instance, and you should immediately quit.On macOS the system enforces
/// single instance automatically when users try to open a second instance of your
/// app in Finder, and the open-file and open-url events will be emitted for that.
/// However when users start your app in command line the system's single instance
/// mechanism will be bypassed and you have to use this method to ensure single
/// instance.
/// </summary>
/// <param name="newInstanceOpened">Lambda with an array of the second instance’ s command line arguments.
/// The second parameter is the working directory path.</param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken">The cancellation token.</param>
2017-10-14 14:41:11 +02:00
/// <returns>This method returns false if your process is the primary instance of
/// the application and your app should continue loading. And returns true if your
/// process has sent its parameters to another instance, and you should immediately quit.</returns>
2018-09-25 23:10:58 +02:00
public async Task < bool > RequestSingleInstanceLockAsync ( Action < string [ ] , string > newInstanceOpened , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2018-09-25 23:10:58 +02:00
BridgeConnector . Socket . On ( "appRequestSingleInstanceLockCompleted" , ( success ) = >
2017-11-13 20:47:31 +01:00
{
2018-09-25 23:10:58 +02:00
BridgeConnector . Socket . Off ( "appRequestSingleInstanceLockCompleted" ) ;
2017-11-13 20:47:31 +01:00
taskCompletionSource . SetResult ( ( bool ) success ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2018-09-25 23:10:58 +02:00
BridgeConnector . Socket . Off ( "secondInstance" ) ;
BridgeConnector . Socket . On ( "secondInstance" , ( result ) = >
2017-11-13 20:47:31 +01:00
{
JArray results = ( JArray ) result ;
string [ ] args = results . First . ToObject < string [ ] > ( ) ;
string workdirectory = results . Last . ToObject < string > ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
newInstanceOpened ( args , workdirectory ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2018-09-25 23:10:58 +02:00
BridgeConnector . Socket . Emit ( "appRequestSingleInstanceLock" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Releases all locks that were created by makeSingleInstance. This will allow
/// multiple instances of the application to once again run side by side.
/// </summary>
2018-09-25 23:10:58 +02:00
public void ReleaseSingleInstanceLock ( )
2017-10-14 00:06:58 +02:00
{
2018-09-25 23:10:58 +02:00
BridgeConnector . Socket . Emit ( "appReleaseSingleInstanceLock" ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Creates an NSUserActivity and sets it as the current activity. The activity is
/// eligible for Handoff to another device afterward.
/// </summary>
/// <param name="type">Uniquely identifies the activity. Maps to NSUserActivity.activityType.</param>
/// <param name="userInfo">App-specific state to store for use by another device.</param>
2017-10-14 17:58:16 +02:00
public void SetUserActivity ( string type , object userInfo )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appSetUserActivity" , type , userInfo ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Creates an NSUserActivity and sets it as the current activity. The activity is
/// eligible for Handoff to another device afterward.
/// </summary>
/// <param name="type">Uniquely identifies the activity. Maps to NSUserActivity.activityType.</param>
/// <param name="userInfo">App-specific state to store for use by another device.</param>
/// <param name="webpageURL">The webpage to load in a browser if no suitable app is installed on the resuming device. The scheme must be http or https.</param>
2017-10-14 17:58:16 +02:00
public void SetUserActivity ( string type , object userInfo , string webpageURL )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appSetUserActivity" , type , userInfo , webpageURL ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// The type of the currently running activity.
/// </summary>
/// <returns></returns>
2017-11-13 20:47:31 +01:00
public async Task < string > GetCurrentActivityTypeAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < string > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appGetCurrentActivityTypeCompleted" , ( activityType ) = >
{
BridgeConnector . Socket . Off ( "appGetCurrentActivityTypeCompleted" ) ;
taskCompletionSource . SetResult ( activityType . ToString ( ) ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appGetCurrentActivityType" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Changes the Application User Model ID to id.
/// </summary>
/// <param name="id"></param>
2017-10-14 17:58:16 +02:00
public void SetAppUserModelId ( string id )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appSetAppUserModelId" , id ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Imports the certificate in pkcs12 format into the platform certificate store.
/// callback is called with the result of import operation, a value of 0 indicates
/// success while any other value indicates failure according to chromium net_error_list.
/// </summary>
/// <param name="options"></param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken">The cancellation token.</param>
2017-10-14 14:41:11 +02:00
/// <returns>Result of import. Value of 0 indicates success.</returns>
2017-11-13 20:47:31 +01:00
public async Task < int > ImportCertificateAsync ( ImportCertificateOptions options , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < int > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appImportCertificateCompleted" , ( result ) = >
{
BridgeConnector . Socket . Off ( "appImportCertificateCompleted" ) ;
taskCompletionSource . SetResult ( ( int ) result ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appImportCertificate" , JObject . FromObject ( options , _jsonSerializer ) ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Memory and cpu usage statistics of all the processes associated with the app.
/// </summary>
2018-09-25 23:10:58 +02:00
/// <returns>Array of ProcessMetric objects that correspond to memory and cpu usage
/// statistics of all the processes associated with the app.</returns>
2017-11-13 20:47:31 +01:00
public async Task < ProcessMetric [ ] > GetAppMetricsAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < ProcessMetric [ ] > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appGetAppMetricsCompleted" , ( result ) = >
{
BridgeConnector . Socket . Off ( "appGetAppMetricsCompleted" ) ;
var processMetrics = ( ( JArray ) result ) . ToObject < ProcessMetric [ ] > ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
taskCompletionSource . SetResult ( processMetrics ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appGetAppMetrics" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// The Graphics Feature Status from chrome://gpu/.
/// </summary>
/// <returns></returns>
2017-11-13 20:47:31 +01:00
public async Task < GPUFeatureStatus > GetGpuFeatureStatusAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < GPUFeatureStatus > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appGetGpuFeatureStatusCompleted" , ( result ) = >
{
BridgeConnector . Socket . Off ( "appGetGpuFeatureStatusCompleted" ) ;
var gpuFeatureStatus = ( ( JObject ) result ) . ToObject < GPUFeatureStatus > ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
taskCompletionSource . SetResult ( gpuFeatureStatus ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appGetGpuFeatureStatus" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Sets the counter badge for current app. Setting the count to 0 will hide the
/// badge. On macOS it shows on the dock icon. On Linux it only works for Unity
/// launcher, Note: Unity launcher requires the existence of a.desktop file to
/// work, for more information please read Desktop Environment Integration.
/// </summary>
/// <returns>Whether the call succeeded.</returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > SetBadgeCountAsync ( int count , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appSetBadgeCountCompleted" , ( success ) = >
{
BridgeConnector . Socket . Off ( "appSetBadgeCountCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) success ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2019-11-30 01:30:22 +01:00
BridgeConnector . Socket . Emit ( "appSetBadgeCount" , count ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// The current value displayed in the counter badge.
/// </summary>
/// <returns></returns>
2017-11-13 20:47:31 +01:00
public async Task < int > GetBadgeCountAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < int > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appGetBadgeCountCompleted" , ( count ) = >
{
BridgeConnector . Socket . Off ( "appGetBadgeCountCompleted" ) ;
taskCompletionSource . SetResult ( ( int ) count ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appGetBadgeCount" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2019-11-30 01:30:22 +01:00
/// <summary>
/// Manipulate the command line arguments for your app that Chromium reads.
/// </summary>
public CommandLine CommandLine { get ; internal set ; }
2017-10-14 14:41:11 +02:00
/// <summary>
/// Whether the current desktop environment is Unity launcher.
/// </summary>
/// <returns></returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > IsUnityRunningAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appIsUnityRunningCompleted" , ( isUnityRunning ) = >
{
BridgeConnector . Socket . Off ( "appIsUnityRunningCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) isUnityRunning ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appIsUnityRunning" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// If you provided path and args options to app.setLoginItemSettings then you need
/// to pass the same arguments here for openAtLogin to be set correctly. Note: This
/// API has no effect on MAS builds.
/// </summary>
/// <returns></returns>
2017-11-13 20:47:31 +01:00
public async Task < LoginItemSettings > GetLoginItemSettingsAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < LoginItemSettings > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appGetLoginItemSettingsCompleted" , ( loginItemSettings ) = >
{
BridgeConnector . Socket . Off ( "appGetLoginItemSettingsCompleted" ) ;
taskCompletionSource . SetResult ( ( LoginItemSettings ) loginItemSettings ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appGetLoginItemSettings" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// If you provided path and args options to app.setLoginItemSettings then you need
/// to pass the same arguments here for openAtLogin to be set correctly. Note: This
/// API has no effect on MAS builds.
/// </summary>
/// <param name="options"></param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken">The cancellation token.</param>
2017-10-14 14:41:11 +02:00
/// <returns></returns>
2017-11-13 20:47:31 +01:00
public async Task < LoginItemSettings > GetLoginItemSettingsAsync ( LoginItemSettingsOptions options , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < LoginItemSettings > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appGetLoginItemSettingsCompleted" , ( loginItemSettings ) = >
{
BridgeConnector . Socket . Off ( "appGetLoginItemSettingsCompleted" ) ;
taskCompletionSource . SetResult ( ( LoginItemSettings ) loginItemSettings ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appGetLoginItemSettings" , JObject . FromObject ( options , _jsonSerializer ) ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Set the app's login item settings. To work with Electron's autoUpdater on
/// Windows, which uses Squirrel, you'll want to set the launch path to Update.exe,
/// and pass arguments that specify your application name.
/// </summary>
/// <param name="loginSettings"></param>
2017-10-14 17:58:16 +02:00
public void SetLoginItemSettings ( LoginSettings loginSettings )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appSetLoginItemSettings" , JObject . FromObject ( loginSettings , _jsonSerializer ) ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// This API will return true if the use of assistive technologies,
/// such as screen readers, has been detected.
/// See https://www.chromium.org/developers/design-documents/accessibility for more details.
/// </summary>
/// <returns>true if Chrome’ s accessibility support is enabled, false otherwise.</returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > IsAccessibilitySupportEnabledAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appIsAccessibilitySupportEnabledCompleted" , ( isAccessibilitySupportEnabled ) = >
{
BridgeConnector . Socket . Off ( "appIsAccessibilitySupportEnabledCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) isAccessibilitySupportEnabled ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appIsAccessibilitySupportEnabled" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Set the about panel options. This will override the values defined in the app's
/// .plist file. See the Apple docs for more details.
/// </summary>
/// <param name="options"></param>
2017-10-14 17:58:16 +02:00
public void SetAboutPanelOptions ( AboutPanelOptions options )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appSetAboutPanelOptions" , JObject . FromObject ( options , _jsonSerializer ) ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// When critical is passed, the dock icon will bounce until either the application
/// becomes active or the request is canceled.When informational is passed, the
/// dock icon will bounce for one second.However, the request remains active until
/// either the application becomes active or the request is canceled.
/// </summary>
/// <param name="type"></param>
2017-11-13 20:47:31 +01:00
/// <param name="cancellationToken"></param>
2017-10-14 14:41:11 +02:00
/// <returns></returns>
2017-11-13 20:47:31 +01:00
public async Task < int > DockBounceAsync ( DockBounceType type , CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < int > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appDockBounceCompleted" , ( id ) = >
{
BridgeConnector . Socket . Off ( "appDockBounceCompleted" ) ;
taskCompletionSource . SetResult ( ( int ) id ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appDockBounce" , type . ToString ( ) ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Cancel the bounce of id.
/// </summary>
/// <param name="id"></param>
2017-10-14 17:58:16 +02:00
public void DockCancelBounce ( int id )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appDockCancelBounce" , id ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Bounces the Downloads stack if the filePath is inside the Downloads folder.
/// </summary>
/// <param name="filePath"></param>
2017-10-14 17:58:16 +02:00
public void DockDownloadFinished ( string filePath )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appDockDownloadFinished" , filePath ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Sets the string to be displayed in the dock’ s badging area.
/// </summary>
/// <param name="text"></param>
2017-10-14 17:58:16 +02:00
public void DockSetBadge ( string text )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appDockSetBadge" , text ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Gets the string to be displayed in the dock’ s badging area.
/// </summary>
/// <returns></returns>
2017-11-13 20:47:31 +01:00
public async Task < string > DockGetBadgeAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < string > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appDockGetBadgeCompleted" , ( text ) = >
{
BridgeConnector . Socket . Off ( "appDockGetBadgeCompleted" ) ;
taskCompletionSource . SetResult ( ( string ) text ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appDockGetBadge" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Hides the dock icon.
/// </summary>
2017-10-14 17:58:16 +02:00
public void DockHide ( )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appDockHide" ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Shows the dock icon.
/// </summary>
2017-10-14 17:58:16 +02:00
public void DockShow ( )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appDockShow" ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Whether the dock icon is visible. The app.dock.show() call is asynchronous
/// so this method might not return true immediately after that call.
/// </summary>
/// <returns></returns>
2017-11-13 20:47:31 +01:00
public async Task < bool > DockIsVisibleAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
cancellationToken . ThrowIfCancellationRequested ( ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
var taskCompletionSource = new TaskCompletionSource < bool > ( ) ;
using ( cancellationToken . Register ( ( ) = > taskCompletionSource . TrySetCanceled ( ) ) )
2017-10-14 00:06:58 +02:00
{
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . On ( "appDockIsVisibleCompleted" , ( isVisible ) = >
{
BridgeConnector . Socket . Off ( "appDockIsVisibleCompleted" ) ;
taskCompletionSource . SetResult ( ( bool ) isVisible ) ;
} ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
BridgeConnector . Socket . Emit ( "appDockIsVisible" ) ;
2017-10-14 00:06:58 +02:00
2017-11-13 20:47:31 +01:00
return await taskCompletionSource . Task
. ConfigureAwait ( false ) ;
}
2017-10-14 00:06:58 +02:00
}
2017-10-24 21:43:27 +02:00
// TODO: Menu lösung für macOS muss gemacht werden und imeplementiert
2017-10-14 14:41:11 +02:00
/// <summary>
/// Sets the application's dock menu.
/// </summary>
2017-10-14 17:58:16 +02:00
public void DockSetMenu ( )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appDockSetMenu" ) ;
2017-10-14 00:06:58 +02:00
}
2017-10-14 14:41:11 +02:00
/// <summary>
/// Sets the image associated with this dock icon.
/// </summary>
/// <param name="image"></param>
2017-10-14 17:58:16 +02:00
public void DockSetIcon ( string image )
2017-10-14 00:06:58 +02:00
{
2017-10-14 17:58:16 +02:00
BridgeConnector . Socket . Emit ( "appDockSetIcon" , image ) ;
2017-10-14 00:06:58 +02:00
}
2017-11-10 03:11:13 +01:00
internal void PreventQuit ( )
{
_preventQuit = true ;
}
private bool _preventQuit = false ;
2017-10-03 03:28:56 +02:00
}
}