diff --git a/ElectronNET.API/Dialog.cs b/ElectronNET.API/Dialog.cs index cb5b520a..13984833 100644 --- a/ElectronNET.API/Dialog.cs +++ b/ElectronNET.API/Dialog.cs @@ -3,7 +3,9 @@ using Newtonsoft.Json.Linq; using Newtonsoft.Json.Serialization; using System; +using System.Collections.Generic; using System.Threading.Tasks; +using System.Web; namespace ElectronNET.API { @@ -54,7 +56,12 @@ public Task ShowOpenDialogAsync(BrowserWindow browserWindow, OpenDialo BridgeConnector.Socket.Off("showOpenDialogComplete" + guid); var result = ((JArray)filePaths).ToObject(); - taskCompletionSource.SetResult(result); + var list = new List(); + foreach (var item in result) + { + list.Add(HttpUtility.UrlDecode(item)); + } + taskCompletionSource.SetResult(list.ToArray()); }); diff --git a/ElectronNET.API/ElectronNET.API.csproj b/ElectronNET.API/ElectronNET.API.csproj index 83e08473..00eac8cf 100644 --- a/ElectronNET.API/ElectronNET.API.csproj +++ b/ElectronNET.API/ElectronNET.API.csproj @@ -16,6 +16,7 @@ This package contains the API to access the "native" electron API. electron aspnetcore Changelog: https://github.com/ElectronNET/Electron.NET/blob/master/Changelog.md https://raw.githubusercontent.com/ElectronNET/Electron.NET/master/assets/images/electron.net-logo-square.png + 1.0.0.2 @@ -31,8 +32,9 @@ This package contains the API to access the "native" electron API. + - + diff --git a/ElectronNET.API/IpcMain.cs b/ElectronNET.API/IpcMain.cs index fedc900a..2af381be 100644 --- a/ElectronNET.API/IpcMain.cs +++ b/ElectronNET.API/IpcMain.cs @@ -46,6 +46,7 @@ internal static IpcMain Instance public void On(string channel, Action listener) { BridgeConnector.Socket.Emit("registerIpcMainChannel", channel); + BridgeConnector.Socket.Off(channel); BridgeConnector.Socket.On(channel, (args) => { List objectArray = FormatArguments(args); diff --git a/ElectronNET.CLI/ElectronNET.CLI.csproj b/ElectronNET.CLI/ElectronNET.CLI.csproj index e2f4202c..c5940055 100644 --- a/ElectronNET.CLI/ElectronNET.CLI.csproj +++ b/ElectronNET.CLI/ElectronNET.CLI.csproj @@ -9,7 +9,7 @@ true ..\artifacts ElectronNET.CLI - 1.0.0 + 1.0.4.2 Gregor Biswanger, Robert Muehsig Electron.NET diff --git a/ElectronNET.Host/api/app.js b/ElectronNET.Host/api/app.js index 997591ba..8638b5b2 100644 --- a/ElectronNET.Host/api/app.js +++ b/ElectronNET.Host/api/app.js @@ -16,44 +16,44 @@ module.exports = function (socket, app) { }); socket.on('register-app-window-all-closed-event', function (id) { app.on('window-all-closed', function () { - socket.emit('app-window-all-closed' + id); + global.elesocket.emit('app-window-all-closed' + id); }); }); socket.on('register-app-before-quit-event', function (id) { app.on('before-quit', function (event) { event.preventDefault(); - socket.emit('app-before-quit' + id); + global.elesocket.emit('app-before-quit' + id); }); }); socket.on('register-app-will-quit-event', function (id) { app.on('will-quit', function (event) { event.preventDefault(); - socket.emit('app-will-quit' + id); + global.elesocket.emit('app-will-quit' + id); }); }); socket.on('register-app-browser-window-blur-event', function (id) { app.on('browser-window-blur', function () { - socket.emit('app-browser-window-blur' + id); + global.elesocket.emit('app-browser-window-blur' + id); }); }); socket.on('register-app-browser-window-focus-event', function (id) { app.on('browser-window-focus', function () { - socket.emit('app-browser-window-focus' + id); + global.elesocket.emit('app-browser-window-focus' + id); }); }); socket.on('register-app-browser-window-created-event', function (id) { app.on('browser-window-created', function () { - socket.emit('app-browser-window-created' + id); + global.elesocket.emit('app-browser-window-created' + id); }); }); socket.on('register-app-web-contents-created-event', function (id) { app.on('web-contents-created', function () { - socket.emit('app-web-contents-created' + id); + global.elesocket.emit('app-web-contents-created' + id); }); }); socket.on('register-app-accessibility-support-changed-event', function (id) { app.on('accessibility-support-changed', function (event, accessibilitySupportEnabled) { - socket.emit('app-accessibility-support-changed' + id, accessibilitySupportEnabled); + global.elesocket.emit('app-accessibility-support-changed' + id, accessibilitySupportEnabled); }); }); socket.on('appQuit', function () { @@ -77,11 +77,11 @@ module.exports = function (socket, app) { }); socket.on('appGetAppPath', function () { var path = app.getAppPath(); - socket.emit('appGetAppPathCompleted', path); + global.elesocket.emit('appGetAppPathCompleted', path); }); socket.on('appGetPath', function (name) { var path = app.getPath(name); - socket.emit('appGetPathCompleted', path); + global.elesocket.emit('appGetPathCompleted', path); }); // const nativeImages = {}; // function addNativeImage(nativeImage: Electron.NativeImage) { @@ -95,12 +95,12 @@ module.exports = function (socket, app) { socket.on('appGetFileIcon', function (path, options) { if (options) { app.getFileIcon(path, options, function (error, nativeImage) { - socket.emit('appGetFileIconCompleted', [error, nativeImage]); + global.elesocket.emit('appGetFileIconCompleted', [error, nativeImage]); }); } else { app.getFileIcon(path, function (error, nativeImage) { - socket.emit('appGetFileIconCompleted', [error, nativeImage]); + global.elesocket.emit('appGetFileIconCompleted', [error, nativeImage]); }); } }); @@ -109,18 +109,18 @@ module.exports = function (socket, app) { }); socket.on('appGetVersion', function () { var version = app.getVersion(); - socket.emit('appGetVersionCompleted', version); + global.elesocket.emit('appGetVersionCompleted', version); }); socket.on('appGetName', function () { var name = app.getName(); - socket.emit('appGetNameCompleted', name); + global.elesocket.emit('appGetNameCompleted', name); }); socket.on('appSetName', function (name) { app.setName(name); }); socket.on('appGetLocale', function () { var locale = app.getLocale(); - socket.emit('appGetLocaleCompleted', locale); + global.elesocket.emit('appGetLocaleCompleted', locale); }); socket.on('appAddRecentDocument', function (path) { app.addRecentDocument(path); @@ -130,32 +130,32 @@ module.exports = function (socket, app) { }); socket.on('appSetAsDefaultProtocolClient', function (protocol, path, args) { var success = app.setAsDefaultProtocolClient(protocol, path, args); - socket.emit('appSetAsDefaultProtocolClientCompleted', success); + global.elesocket.emit('appSetAsDefaultProtocolClientCompleted', success); }); socket.on('appRemoveAsDefaultProtocolClient', function (protocol, path, args) { var success = app.removeAsDefaultProtocolClient(protocol, path, args); - socket.emit('appRemoveAsDefaultProtocolClientCompleted', success); + global.elesocket.emit('appRemoveAsDefaultProtocolClientCompleted', success); }); socket.on('appIsDefaultProtocolClient', function (protocol, path, args) { var success = app.isDefaultProtocolClient(protocol, path, args); - socket.emit('appIsDefaultProtocolClientCompleted', success); + global.elesocket.emit('appIsDefaultProtocolClientCompleted', success); }); socket.on('appSetUserTasks', function (tasks) { var success = app.setUserTasks(tasks); - socket.emit('appSetUserTasksCompleted', success); + global.elesocket.emit('appSetUserTasksCompleted', success); }); socket.on('appGetJumpListSettings', function () { var jumpListSettings = app.getJumpListSettings(); - socket.emit('appGetJumpListSettingsCompleted', jumpListSettings); + global.elesocket.emit('appGetJumpListSettingsCompleted', jumpListSettings); }); socket.on('appSetJumpList', function (categories) { app.setJumpList(categories); }); socket.on('appMakeSingleInstance', function () { var success = app.makeSingleInstance(function (args, workingDirectory) { - socket.emit('newInstanceOpened', [args, workingDirectory]); + global.elesocket.emit('newInstanceOpened', [args, workingDirectory]); }); - socket.emit('appMakeSingleInstanceCompleted', success); + global.elesocket.emit('appMakeSingleInstanceCompleted', success); }); socket.on('appReleaseSingleInstance', function () { app.releaseSingleInstance(); @@ -165,48 +165,48 @@ module.exports = function (socket, app) { }); socket.on('appGetCurrentActivityType', function () { var activityType = app.getCurrentActivityType(); - socket.emit('appGetCurrentActivityTypeCompleted', activityType); + global.elesocket.emit('appGetCurrentActivityTypeCompleted', activityType); }); socket.on('appSetAppUserModelId', function (id) { app.setAppUserModelId(id); }); socket.on('appImportCertificate', function (options) { app.importCertificate(options, function (result) { - socket.emit('appImportCertificateCompleted', result); + global.elesocket.emit('appImportCertificateCompleted', result); }); }); socket.on('appGetAppMetrics', function () { var processMetrics = app.getAppMetrics(); - socket.emit('appGetAppMetricsCompleted', processMetrics); + global.elesocket.emit('appGetAppMetricsCompleted', processMetrics); }); socket.on('appGetGpuFeatureStatus', function () { // TS Workaround - TS say getGpuFeatureStatus - but it is getGPUFeatureStatus var x = app; var gpuFeatureStatus = x.getGPUFeatureStatus(); - socket.emit('appGetGpuFeatureStatusCompleted', gpuFeatureStatus); + global.elesocket.emit('appGetGpuFeatureStatusCompleted', gpuFeatureStatus); }); socket.on('appSetBadgeCount', function (count) { var success = app.setBadgeCount(count); - socket.emit('appSetBadgeCountCompleted', success); + global.elesocket.emit('appSetBadgeCountCompleted', success); }); socket.on('appGetBadgeCount', function () { var count = app.getBadgeCount(); - socket.emit('appGetBadgeCountCompleted', count); + global.elesocket.emit('appGetBadgeCountCompleted', count); }); socket.on('appIsUnityRunning', function () { var isUnityRunning = app.isUnityRunning(); - socket.emit('appIsUnityRunningCompleted', isUnityRunning); + global.elesocket.emit('appIsUnityRunningCompleted', isUnityRunning); }); socket.on('appGetLoginItemSettings', function (options) { var loginItemSettings = app.getLoginItemSettings(options); - socket.emit('appGetLoginItemSettingsCompleted', loginItemSettings); + global.elesocket.emit('appGetLoginItemSettingsCompleted', loginItemSettings); }); socket.on('appSetLoginItemSettings', function (settings) { app.setLoginItemSettings(settings); }); socket.on('appIsAccessibilitySupportEnabled', function () { var isAccessibilitySupportEnabled = app.isAccessibilitySupportEnabled(); - socket.emit('appIsAccessibilitySupportEnabledCompleted', isAccessibilitySupportEnabled); + global.elesocket.emit('appIsAccessibilitySupportEnabledCompleted', isAccessibilitySupportEnabled); }); socket.on('appSetAboutPanelOptions', function (options) { app.setAboutPanelOptions(options); @@ -222,7 +222,7 @@ module.exports = function (socket, app) { }); socket.on('appDockBounce', function (type) { var id = app.dock.bounce(type); - socket.emit('appDockBounceCompleted', id); + global.elesocket.emit('appDockBounceCompleted', id); }); socket.on('appDockCancelBounce', function (id) { app.dock.cancelBounce(id); @@ -235,7 +235,7 @@ module.exports = function (socket, app) { }); socket.on('appDockGetBadge', function () { var text = app.dock.getBadge(); - socket.emit('appDockGetBadgeCompleted', text); + global.elesocket.emit('appDockGetBadgeCompleted', text); }); socket.on('appDockHide', function () { app.dock.hide(); @@ -245,7 +245,7 @@ module.exports = function (socket, app) { }); socket.on('appDockIsVisible', function () { var isVisible = app.dock.isVisible(); - socket.emit('appDockIsVisibleCompleted', isVisible); + global.elesocket.emit('appDockIsVisibleCompleted', isVisible); }); // TODO: Menü Lösung muss noch implementiert werden socket.on('appDockSetMenu', function (menu) { diff --git a/ElectronNET.Host/api/browserWindows.js b/ElectronNET.Host/api/browserWindows.js index 8ccc9a6f..49284adc 100644 --- a/ElectronNET.Host/api/browserWindows.js +++ b/ElectronNET.Host/api/browserWindows.js @@ -6,152 +6,152 @@ var windows = []; module.exports = function (socket) { socket.on('register-browserWindow-ready-to-show', function (id) { getWindowById(id).on('ready-to-show', function () { - socket.emit('browserWindow-ready-to-show' + id); + global.elesocket.emit('browserWindow-ready-to-show' + id); }); }); socket.on('register-browserWindow-page-title-updated', function (id) { getWindowById(id).on('page-title-updated', function (event, title) { - socket.emit('browserWindow-page-title-updated' + id, title); + global.elesocket.emit('browserWindow-page-title-updated' + id, title); }); }); socket.on('register-browserWindow-close', function (id) { getWindowById(id).on('close', function () { - socket.emit('browserWindow-close' + id); + global.elesocket.emit('browserWindow-close' + id); }); }); socket.on('register-browserWindow-closed', function (id) { getWindowById(id).on('closed', function () { - socket.emit('browserWindow-closed' + id); + global.elesocket.emit('browserWindow-closed' + id); }); }); socket.on('register-browserWindow-session-end', function (id) { getWindowById(id).on('session-end', function () { - socket.emit('browserWindow-session-end' + id); + global.elesocket.emit('browserWindow-session-end' + id); }); }); socket.on('register-browserWindow-unresponsive', function (id) { getWindowById(id).on('unresponsive', function () { - socket.emit('browserWindow-unresponsive' + id); + global.elesocket.emit('browserWindow-unresponsive' + id); }); }); socket.on('register-browserWindow-responsive', function (id) { getWindowById(id).on('responsive', function () { - socket.emit('browserWindow-responsive' + id); + global.elesocket.emit('browserWindow-responsive' + id); }); }); socket.on('register-browserWindow-blur', function (id) { getWindowById(id).on('blur', function () { - socket.emit('browserWindow-blur' + id); + global.elesocket.emit('browserWindow-blur' + id); }); }); socket.on('register-browserWindow-focus', function (id) { getWindowById(id).on('focus', function () { - socket.emit('browserWindow-focus' + id); + global.elesocket.emit('browserWindow-focus' + id); }); }); socket.on('register-browserWindow-show', function (id) { getWindowById(id).on('show', function () { - socket.emit('browserWindow-show' + id); + global.elesocket.emit('browserWindow-show' + id); }); }); socket.on('register-browserWindow-hide', function (id) { getWindowById(id).on('hide', function () { - socket.emit('browserWindow-hide' + id); + global.elesocket.emit('browserWindow-hide' + id); }); }); socket.on('register-browserWindow-maximize', function (id) { getWindowById(id).on('maximize', function () { - socket.emit('browserWindow-maximize' + id); + global.elesocket.emit('browserWindow-maximize' + id); }); }); socket.on('register-browserWindow-unmaximize', function (id) { getWindowById(id).on('unmaximize', function () { - socket.emit('browserWindow-unmaximize' + id); + global.elesocket.emit('browserWindow-unmaximize' + id); }); }); socket.on('register-browserWindow-minimize', function (id) { getWindowById(id).on('minimize', function () { - socket.emit('browserWindow-minimize' + id); + global.elesocket.emit('browserWindow-minimize' + id); }); }); socket.on('register-browserWindow-restore', function (id) { getWindowById(id).on('restore', function () { - socket.emit('browserWindow-restore' + id); + global.elesocket.emit('browserWindow-restore' + id); }); }); socket.on('register-browserWindow-resize', function (id) { getWindowById(id).on('resize', function () { - socket.emit('browserWindow-resize' + id); + global.elesocket.emit('browserWindow-resize' + id); }); }); socket.on('register-browserWindow-move', function (id) { getWindowById(id).on('move', function () { - socket.emit('browserWindow-move' + id); + global.elesocket.emit('browserWindow-move' + id); }); }); socket.on('register-browserWindow-moved', function (id) { getWindowById(id).on('moved', function () { - socket.emit('browserWindow-moved' + id); + global.elesocket.emit('browserWindow-moved' + id); }); }); socket.on('register-browserWindow-enter-full-screen', function (id) { getWindowById(id).on('enter-full-screen', function () { - socket.emit('browserWindow-enter-full-screen' + id); + global.elesocket.emit('browserWindow-enter-full-screen' + id); }); }); socket.on('register-browserWindow-leave-full-screen', function (id) { getWindowById(id).on('leave-full-screen', function () { - socket.emit('browserWindow-leave-full-screen' + id); + global.elesocket.emit('browserWindow-leave-full-screen' + id); }); }); socket.on('register-browserWindow-enter-html-full-screen', function (id) { getWindowById(id).on('enter-html-full-screen', function () { - socket.emit('browserWindow-enter-html-full-screen' + id); + global.elesocket.emit('browserWindow-enter-html-full-screen' + id); }); }); socket.on('register-browserWindow-leave-html-full-screen', function (id) { getWindowById(id).on('leave-html-full-screen', function () { - socket.emit('browserWindow-leave-html-full-screen' + id); + global.elesocket.emit('browserWindow-leave-html-full-screen' + id); }); }); socket.on('register-browserWindow-app-command', function (id) { getWindowById(id).on('app-command', function (event, command) { - socket.emit('browserWindow-app-command' + id, command); + global.elesocket.emit('browserWindow-app-command' + id, command); }); }); socket.on('register-browserWindow-scroll-touch-begin', function (id) { getWindowById(id).on('scroll-touch-begin', function () { - socket.emit('browserWindow-scroll-touch-begin' + id); + global.elesocket.emit('browserWindow-scroll-touch-begin' + id); }); }); socket.on('register-browserWindow-scroll-touch-end', function (id) { getWindowById(id).on('scroll-touch-end', function () { - socket.emit('browserWindow-scroll-touch-end' + id); + global.elesocket.emit('browserWindow-scroll-touch-end' + id); }); }); socket.on('register-browserWindow-scroll-touch-edge', function (id) { getWindowById(id).on('scroll-touch-edge', function () { - socket.emit('browserWindow-scroll-touch-edge' + id); + global.elesocket.emit('browserWindow-scroll-touch-edge' + id); }); }); socket.on('register-browserWindow-swipe', function (id) { getWindowById(id).on('swipe', function (event, direction) { - socket.emit('browserWindow-swipe' + id, direction); + global.elesocket.emit('browserWindow-swipe' + id, direction); }); }); socket.on('register-browserWindow-sheet-begin', function (id) { getWindowById(id).on('sheet-begin', function () { - socket.emit('browserWindow-sheet-begin' + id); + global.elesocket.emit('browserWindow-sheet-begin' + id); }); }); socket.on('register-browserWindow-sheet-end', function (id) { getWindowById(id).on('sheet-end', function () { - socket.emit('browserWindow-sheet-end' + id); + global.elesocket.emit('browserWindow-sheet-end' + id); }); }); socket.on('register-browserWindow-new-window-for-tab', function (id) { getWindowById(id).on('new-window-for-tab', function () { - socket.emit('browserWindow-new-window-for-tab' + id); + global.elesocket.emit('browserWindow-new-window-for-tab' + id); }); }); socket.on('createBrowserWindow', function (options, loadUrl) { @@ -167,7 +167,7 @@ module.exports = function (socket) { windows.splice(index, 1); var ids_1 = []; windows.forEach(function (x) { return ids_1.push(x.id); }); - socket.emit('BrowserWindowClosed', ids_1); + global.elesocket.emit('BrowserWindowClosed', ids_1); } } }; @@ -180,245 +180,242 @@ module.exports = function (socket) { window.loadURL(loadUrl); } windows.push(window); - socket.emit('BrowserWindowCreated', window.id); + global.elesocket.emit('BrowserWindowCreated', window.id); }); socket.on('browserWindowDestroy', function (id) { - getWindowById(id).destroy(); + getWindowById(id) && getWindowById(id).destroy(); }); socket.on('browserWindowClose', function (id) { - getWindowById(id).close(); + getWindowById(id) && getWindowById(id).close(); }); socket.on('browserWindowFocus', function (id) { - getWindowById(id).focus(); + getWindowById(id) && getWindowById(id).focus(); }); socket.on('browserWindowBlur', function (id) { - getWindowById(id).blur(); + getWindowById(id) && getWindowById(id).blur(); }); socket.on('browserWindowIsFocused', function (id) { var isFocused = getWindowById(id).isFocused(); - socket.emit('browserWindow-isFocused-completed', isFocused); + global.elesocket.emit('browserWindow-isFocused-completed', isFocused); }); socket.on('browserWindowIsDestroyed', function (id) { var isDestroyed = getWindowById(id).isDestroyed(); - socket.emit('browserWindow-isDestroyed-completed', isDestroyed); + global.elesocket.emit('browserWindow-isDestroyed-completed', isDestroyed); }); socket.on('browserWindowShow', function (id) { - getWindowById(id).show(); + getWindowById(id) && getWindowById(id).show(); }); socket.on('browserWindowShowInactive', function (id) { - getWindowById(id).showInactive(); + getWindowById(id) && getWindowById(id).showInactive(); }); socket.on('browserWindowHide', function (id) { - getWindowById(id).hide(); + getWindowById(id) && getWindowById(id).hide(); }); socket.on('browserWindowIsVisible', function (id) { var isVisible = getWindowById(id).isVisible(); - socket.emit('browserWindow-isVisible-completed', isVisible); + global.elesocket.emit('browserWindow-isVisible-completed', isVisible); }); socket.on('browserWindowIsModal', function (id) { var isModal = getWindowById(id).isModal(); - socket.emit('browserWindow-isModal-completed', isModal); + global.elesocket.emit('browserWindow-isModal-completed', isModal); }); socket.on('browserWindowMaximize', function (id) { - getWindowById(id).maximize(); + getWindowById(id) && getWindowById(id).maximize(); }); socket.on('browserWindowUnmaximize', function (id) { - getWindowById(id).unmaximize(); + getWindowById(id) && getWindowById(id).unmaximize(); }); socket.on('browserWindowIsMaximized', function (id) { var isMaximized = getWindowById(id).isMaximized(); - socket.emit('browserWindow-isMaximized-completed', isMaximized); + global.elesocket.emit('browserWindow-isMaximized-completed', isMaximized); }); socket.on('browserWindowMinimize', function (id) { - getWindowById(id).minimize(); + getWindowById(id) && getWindowById(id).minimize(); }); socket.on('browserWindowRestore', function (id) { - getWindowById(id).restore(); + getWindowById(id) && getWindowById(id).restore(); }); socket.on('browserWindowIsMinimized', function (id) { var isMinimized = getWindowById(id).isMinimized(); - socket.emit('browserWindow-isMinimized-completed', isMinimized); + global.elesocket.emit('browserWindow-isMinimized-completed', isMinimized); }); socket.on('browserWindowSetFullScreen', function (id, fullscreen) { - getWindowById(id).setFullScreen(fullscreen); + getWindowById(id) && getWindowById(id).setFullScreen(fullscreen); }); socket.on('browserWindowIsFullScreen', function (id) { var isFullScreen = getWindowById(id).isFullScreen(); - socket.emit('browserWindow-isFullScreen-completed', isFullScreen); + global.elesocket.emit('browserWindow-isFullScreen-completed', isFullScreen); }); socket.on('browserWindowSetAspectRatio', function (id, aspectRatio, extraSize) { - getWindowById(id).setAspectRatio(aspectRatio, extraSize); + getWindowById(id) && getWindowById(id).setAspectRatio(aspectRatio, extraSize); }); socket.on('browserWindowPreviewFile', function (id, path, displayname) { - getWindowById(id).previewFile(path, displayname); + getWindowById(id) && getWindowById(id).previewFile(path, displayname); }); socket.on('browserWindowCloseFilePreview', function (id) { - getWindowById(id).closeFilePreview(); + getWindowById(id) && getWindowById(id).closeFilePreview(); }); socket.on('browserWindowSetBounds', function (id, bounds, animate) { - getWindowById(id).setBounds(bounds, animate); + getWindowById(id) && getWindowById(id).setBounds(bounds, animate); }); socket.on('browserWindowGetBounds', function (id) { var rectangle = getWindowById(id).getBounds(); - socket.emit('browserWindow-getBounds-completed', rectangle); + global.elesocket.emit('browserWindow-getBounds-completed', rectangle); }); socket.on('browserWindowSetContentBounds', function (id, bounds, animate) { getWindowById(id).setContentBounds(bounds, animate); }); socket.on('browserWindowGetContentBounds', function (id) { var rectangle = getWindowById(id).getContentBounds(); - socket.emit('browserWindow-getContentBounds-completed', rectangle); + global.elesocket.emit('browserWindow-getContentBounds-completed', rectangle); }); socket.on('browserWindowSetSize', function (id, width, height, animate) { - getWindowById(id).setSize(width, height, animate); + getWindowById(id) && getWindowById(id).setSize(width, height, animate); }); socket.on('browserWindowGetSize', function (id) { var size = getWindowById(id).getSize(); - socket.emit('browserWindow-getSize-completed', size); + global.elesocket.emit('browserWindow-getSize-completed', size); }); socket.on('browserWindowSetContentSize', function (id, width, height, animate) { - getWindowById(id).setContentSize(width, height, animate); + getWindowById(id) && getWindowById(id).setContentSize(width, height, animate); }); socket.on('browserWindowGetContentSize', function (id) { var size = getWindowById(id).getContentSize(); - socket.emit('browserWindow-getContentSize-completed', size); + global.elesocket.emit('browserWindow-getContentSize-completed', size); }); socket.on('browserWindowSetMinimumSize', function (id, width, height) { - getWindowById(id).setMinimumSize(width, height); + getWindowById(id) && getWindowById(id).setMinimumSize(width, height); }); socket.on('browserWindowGetMinimumSize', function (id) { var size = getWindowById(id).getMinimumSize(); - socket.emit('browserWindow-getMinimumSize-completed', size); + global.elesocket.emit('browserWindow-getMinimumSize-completed', size); }); socket.on('browserWindowSetMaximumSize', function (id, width, height) { - getWindowById(id).setMaximumSize(width, height); + getWindowById(id) && getWindowById(id).setMaximumSize(width, height); }); socket.on('browserWindowGetMaximumSize', function (id) { var size = getWindowById(id).getMaximumSize(); - socket.emit('browserWindow-getMaximumSize-completed', size); + global.elesocket.emit('browserWindow-getMaximumSize-completed', size); }); socket.on('browserWindowSetResizable', function (id, resizable) { - getWindowById(id).setResizable(resizable); + getWindowById(id) && getWindowById(id).setResizable(resizable); }); socket.on('browserWindowIsResizable', function (id) { var resizable = getWindowById(id).isResizable(); - socket.emit('browserWindow-isResizable-completed', resizable); + global.elesocket.emit('browserWindow-isResizable-completed', resizable); }); socket.on('browserWindowSetMovable', function (id, movable) { - getWindowById(id).setMovable(movable); + getWindowById(id) && getWindowById(id).setMovable(movable); }); socket.on('browserWindowIsMovable', function (id) { var movable = getWindowById(id).isMovable(); - socket.emit('browserWindow-isMovable-completed', movable); + global.elesocket.emit('browserWindow-isMovable-completed', movable); }); socket.on('browserWindowSetMinimizable', function (id, minimizable) { - getWindowById(id).setMinimizable(minimizable); + getWindowById(id) && getWindowById(id).setMinimizable(minimizable); }); socket.on('browserWindowIsMinimizable', function (id) { var minimizable = getWindowById(id).isMinimizable(); - socket.emit('browserWindow-isMinimizable-completed', minimizable); + global.elesocket.emit('browserWindow-isMinimizable-completed', minimizable); }); socket.on('browserWindowSetMaximizable', function (id, maximizable) { - getWindowById(id).setMaximizable(maximizable); + getWindowById(id) && getWindowById(id).setMaximizable(maximizable); }); socket.on('browserWindowIsMaximizable', function (id) { var maximizable = getWindowById(id).isMaximizable(); - socket.emit('browserWindow-isMaximizable-completed', maximizable); + global.elesocket.emit('browserWindow-isMaximizable-completed', maximizable); }); socket.on('browserWindowSetFullScreenable', function (id, fullscreenable) { - getWindowById(id).setFullScreenable(fullscreenable); + getWindowById(id) && getWindowById(id).setFullScreenable(fullscreenable); }); socket.on('browserWindowIsFullScreenable', function (id) { var fullscreenable = getWindowById(id).isFullScreenable(); - socket.emit('browserWindow-isFullScreenable-completed', fullscreenable); + global.elesocket.emit('browserWindow-isFullScreenable-completed', fullscreenable); }); socket.on('browserWindowSetClosable', function (id, closable) { - getWindowById(id).setClosable(closable); + getWindowById(id) && getWindowById(id).setClosable(closable); }); socket.on('browserWindowIsClosable', function (id) { var closable = getWindowById(id).isClosable(); - socket.emit('browserWindow-isClosable-completed', closable); + global.elesocket.emit('browserWindow-isClosable-completed', closable); }); socket.on('browserWindowSetAlwaysOnTop', function (id, flag, level, relativeLevel) { - getWindowById(id).setAlwaysOnTop(flag, level, relativeLevel); + getWindowById(id) && getWindowById(id).setAlwaysOnTop(flag, level, relativeLevel); }); socket.on('browserWindowIsAlwaysOnTop', function (id) { var isAlwaysOnTop = getWindowById(id).isAlwaysOnTop(); - socket.emit('browserWindow-isAlwaysOnTop-completed', isAlwaysOnTop); + global.elesocket.emit('browserWindow-isAlwaysOnTop-completed', isAlwaysOnTop); }); socket.on('browserWindowCenter', function (id) { - getWindowById(id).center(); + getWindowById(id) && getWindowById(id).center(); }); socket.on('browserWindowSetPosition', function (id, x, y, animate) { - getWindowById(id).setPosition(x, y, animate); + getWindowById(id) && getWindowById(id).setPosition(x, y, animate); }); socket.on('browserWindowGetPosition', function (id) { var position = getWindowById(id).getPosition(); - socket.emit('browserWindow-getPosition-completed', position); + global.elesocket.emit('browserWindow-getPosition-completed', position); }); socket.on('browserWindowSetTitle', function (id, title) { - getWindowById(id).setTitle(title); + getWindowById(id) && getWindowById(id).setTitle(title); }); socket.on('browserWindowGetTitle', function (id) { var title = getWindowById(id).getTitle(); - socket.emit('browserWindow-getTitle-completed', title); - }); - socket.on('browserWindowSetTitle', function (id, title) { - getWindowById(id).setTitle(title); + global.elesocket.emit('browserWindow-getTitle-completed', title); }); socket.on('browserWindowSetSheetOffset', function (id, offsetY, offsetX) { if (offsetX) { - getWindowById(id).setSheetOffset(offsetY, offsetX); + getWindowById(id) && getWindowById(id).setSheetOffset(offsetY, offsetX); } else { - getWindowById(id).setSheetOffset(offsetY); + getWindowById(id) && getWindowById(id).setSheetOffset(offsetY); } }); socket.on('browserWindowFlashFrame', function (id, flag) { - getWindowById(id).flashFrame(flag); + getWindowById(id) && getWindowById(id).flashFrame(flag); }); socket.on('browserWindowSetSkipTaskbar', function (id, skip) { - getWindowById(id).setSkipTaskbar(skip); + getWindowById(id) && getWindowById(id).setSkipTaskbar(skip); }); socket.on('browserWindowSetKiosk', function (id, flag) { - getWindowById(id).setKiosk(flag); + getWindowById(id) && getWindowById(id).setKiosk(flag); }); socket.on('browserWindowIsKiosk', function (id) { var isKiosk = getWindowById(id).isKiosk(); - socket.emit('browserWindow-isKiosk-completed', isKiosk); + global.elesocket.emit('browserWindow-isKiosk-completed', isKiosk); }); socket.on('browserWindowSetRepresentedFilename', function (id, filename) { getWindowById(id).setRepresentedFilename(filename); }); socket.on('browserWindowGetRepresentedFilename', function (id) { var pathname = getWindowById(id).getRepresentedFilename(); - socket.emit('browserWindow-getRepresentedFilename-completed', pathname); + global.elesocket.emit('browserWindow-getRepresentedFilename-completed', pathname); }); socket.on('browserWindowSetDocumentEdited', function (id, edited) { - getWindowById(id).setDocumentEdited(edited); + getWindowById(id) && getWindowById(id).setDocumentEdited(edited); }); socket.on('browserWindowIsDocumentEdited', function (id) { var edited = getWindowById(id).isDocumentEdited(); - socket.emit('browserWindow-isDocumentEdited-completed', edited); + global.elesocket.emit('browserWindow-isDocumentEdited-completed', edited); }); socket.on('browserWindowFocusOnWebView', function (id) { - getWindowById(id).focusOnWebView(); + getWindowById(id) && getWindowById(id).focusOnWebView(); }); socket.on('browserWindowBlurWebView', function (id) { - getWindowById(id).blurWebView(); + getWindowById(id) && getWindowById(id).blurWebView(); }); socket.on('browserWindowLoadURL', function (id, url, options) { getWindowById(id).loadURL(url, options); }); socket.on('browserWindowReload', function (id) { - getWindowById(id).reload(); + getWindowById(id) && getWindowById(id).reload(); }); socket.on('browserWindowSetMenu', function (id, menuItems) { var menu = null; if (menuItems) { menu = electron_1.Menu.buildFromTemplate(menuItems); addMenuItemClickConnector(menu.items, function (id) { - socket.emit("windowMenuItemClicked", id); + global.elesocket.emit("windowMenuItemClicked", id); }); } getWindowById(id).setMenu(menu); @@ -434,75 +431,75 @@ module.exports = function (socket) { }); } socket.on('browserWindowSetProgressBar', function (id, progress) { - getWindowById(id).setProgressBar(progress); + getWindowById(id) && getWindowById(id).setProgressBar(progress); }); socket.on('browserWindowSetHasShadow', function (id, hasShadow) { - getWindowById(id).setHasShadow(hasShadow); + getWindowById(id) && getWindowById(id).setHasShadow(hasShadow); }); socket.on('browserWindowHasShadow', function (id) { var hasShadow = getWindowById(id).hasShadow(); - socket.emit('browserWindow-hasShadow-completed', hasShadow); + global.elesocket.emit('browserWindow-hasShadow-completed', hasShadow); }); socket.on('browserWindowSetThumbarButtons', function (id, thumbarButtons) { thumbarButtons.forEach(function (thumbarButton) { var imagePath = path.join(__dirname.replace('api', ''), 'bin', thumbarButton.icon.toString()); thumbarButton.icon = electron_1.nativeImage.createFromPath(imagePath); thumbarButton.click = function () { - socket.emit("thumbarButtonClicked", thumbarButton["id"]); + global.elesocket.emit("thumbarButtonClicked", thumbarButton["id"]); }; }); var success = getWindowById(id).setThumbarButtons(thumbarButtons); - socket.emit('browserWindowSetThumbarButtons-completed', success); + global.elesocket.emit('browserWindowSetThumbarButtons-completed', success); }); socket.on('browserWindowSetThumbnailClip', function (id, rectangle) { - getWindowById(id).setThumbnailClip(rectangle); + getWindowById(id) && getWindowById(id).setThumbnailClip(rectangle); }); socket.on('browserWindowSetThumbnailToolTip', function (id, toolTip) { - getWindowById(id).setThumbnailToolTip(toolTip); + getWindowById(id) && getWindowById(id).setThumbnailToolTip(toolTip); }); socket.on('browserWindowSetAppDetails', function (id, options) { - getWindowById(id).setAppDetails(options); + getWindowById(id) && getWindowById(id).setAppDetails(options); }); socket.on('browserWindowShowDefinitionForSelection', function (id) { - getWindowById(id).showDefinitionForSelection(); + getWindowById(id) && getWindowById(id).showDefinitionForSelection(); }); socket.on('browserWindowSetAutoHideMenuBar', function (id, hide) { - getWindowById(id).setAutoHideMenuBar(hide); + getWindowById(id) && getWindowById(id).setAutoHideMenuBar(hide); }); socket.on('browserWindowIsMenuBarAutoHide', function (id) { var isMenuBarAutoHide = getWindowById(id).isMenuBarAutoHide(); - socket.emit('browserWindow-isMenuBarAutoHide-completed', isMenuBarAutoHide); + global.elesocket.emit('browserWindow-isMenuBarAutoHide-completed', isMenuBarAutoHide); }); socket.on('browserWindowSetMenuBarVisibility', function (id, visible) { getWindowById(id).setMenuBarVisibility(visible); }); socket.on('browserWindowIsMenuBarVisible', function (id) { var isMenuBarVisible = getWindowById(id).isMenuBarVisible(); - socket.emit('browserWindow-isMenuBarVisible-completed', isMenuBarVisible); + global.elesocket.emit('browserWindow-isMenuBarVisible-completed', isMenuBarVisible); }); socket.on('browserWindowSetVisibleOnAllWorkspaces', function (id, visible) { - getWindowById(id).setVisibleOnAllWorkspaces(visible); + getWindowById(id) && getWindowById(id).setVisibleOnAllWorkspaces(visible); }); socket.on('browserWindowIsVisibleOnAllWorkspaces', function (id) { var isVisibleOnAllWorkspaces = getWindowById(id).isVisibleOnAllWorkspaces(); - socket.emit('browserWindow-isVisibleOnAllWorkspaces-completed', isVisibleOnAllWorkspaces); + global.elesocket.emit('browserWindow-isVisibleOnAllWorkspaces-completed', isVisibleOnAllWorkspaces); }); socket.on('browserWindowSetIgnoreMouseEvents', function (id, ignore) { - getWindowById(id).setIgnoreMouseEvents(ignore); + getWindowById(id) && getWindowById(id).setIgnoreMouseEvents(ignore); }); socket.on('browserWindowSetContentProtection', function (id, enable) { - getWindowById(id).setContentProtection(enable); + getWindowById(id) && getWindowById(id).setContentProtection(enable); }); socket.on('browserWindowSetFocusable', function (id, focusable) { - getWindowById(id).setFocusable(focusable); + getWindowById(id) && getWindowById(id).setFocusable(focusable); }); socket.on('browserWindowSetParentWindow', function (id, parent) { var browserWindow = electron_1.BrowserWindow.fromId(parent.id); - getWindowById(id).setParentWindow(browserWindow); + getWindowById(id) && getWindowById(id).setParentWindow(browserWindow); }); socket.on('browserWindowGetParentWindow', function (id) { var browserWindow = getWindowById(id).getParentWindow(); - socket.emit('browserWindow-getParentWindow-completed', browserWindow.id); + global.elesocket.emit('browserWindow-getParentWindow-completed', browserWindow.id); }); socket.on('browserWindowGetChildWindows', function (id) { var browserWindows = getWindowById(id).getChildWindows(); @@ -510,13 +507,13 @@ module.exports = function (socket) { browserWindows.forEach(function (x) { ids.push(x.id); }); - socket.emit('browserWindow-getChildWindows-completed', ids); + global.elesocket.emit('browserWindow-getChildWindows-completed', ids); }); socket.on('browserWindowSetAutoHideCursor', function (id, autoHide) { - getWindowById(id).setAutoHideCursor(autoHide); + getWindowById(id) && getWindowById(id).setAutoHideCursor(autoHide); }); socket.on('browserWindowSetVibrancy', function (id, type) { - getWindowById(id).setVibrancy(type); + getWindowById(id) && getWindowById(id).setVibrancy(type); }); function getWindowById(id) { for (var index = 0; index < windows.length; index++) { diff --git a/ElectronNET.Host/api/clipboard.js b/ElectronNET.Host/api/clipboard.js index 2f86a6d9..d2b83ac0 100644 --- a/ElectronNET.Host/api/clipboard.js +++ b/ElectronNET.Host/api/clipboard.js @@ -4,35 +4,35 @@ var electron_1 = require("electron"); module.exports = function (socket) { socket.on('clipboard-readText', function (type) { var text = electron_1.clipboard.readText(type); - socket.emit('clipboard-readText-Completed', text); + global.elesocket.emit('clipboard-readText-Completed', text); }); socket.on('clipboard-writeText', function (text, type) { electron_1.clipboard.writeText(text, type); }); socket.on('clipboard-readHTML', function (type) { var content = electron_1.clipboard.readHTML(type); - socket.emit('clipboard-readHTML-Completed', content); + global.elesocket.emit('clipboard-readHTML-Completed', content); }); socket.on('clipboard-writeHTML', function (markup, type) { electron_1.clipboard.writeHTML(markup, type); }); socket.on('clipboard-readRTF', function (type) { var content = electron_1.clipboard.readRTF(type); - socket.emit('clipboard-readRTF-Completed', content); + global.elesocket.emit('clipboard-readRTF-Completed', content); }); socket.on('clipboard-writeRTF', function (text, type) { electron_1.clipboard.writeHTML(text, type); }); socket.on('clipboard-readBookmark', function () { var bookmark = electron_1.clipboard.readBookmark(); - socket.emit('clipboard-readBookmark-Completed', bookmark); + global.elesocket.emit('clipboard-readBookmark-Completed', bookmark); }); socket.on('clipboard-writeBookmark', function (title, url, type) { electron_1.clipboard.writeBookmark(title, url, type); }); socket.on('clipboard-readFindText', function () { var content = electron_1.clipboard.readFindText(); - socket.emit('clipboard-readFindText-Completed', content); + global.elesocket.emit('clipboard-readFindText-Completed', content); }); socket.on('clipboard-writeFindText', function (text) { electron_1.clipboard.writeFindText(text); @@ -42,7 +42,7 @@ module.exports = function (socket) { }); socket.on('clipboard-availableFormats', function (type) { var formats = electron_1.clipboard.availableFormats(type); - socket.emit('clipboard-availableFormats-Completed', formats); + global.elesocket.emit('clipboard-availableFormats-Completed', formats); }); socket.on('clipboard-write', function (data, type) { electron_1.clipboard.write(data, type); diff --git a/ElectronNET.Host/api/dialog.js b/ElectronNET.Host/api/dialog.js index 1e3ef937..0e762ff3 100644 --- a/ElectronNET.Host/api/dialog.js +++ b/ElectronNET.Host/api/dialog.js @@ -6,27 +6,33 @@ module.exports = function (socket) { if ("id" in browserWindow) { var window = electron_1.BrowserWindow.fromId(browserWindow.id); electron_1.dialog.showMessageBox(window, options, function (response, checkboxChecked) { - socket.emit('showMessageBoxComplete' + guid, [response, checkboxChecked]); + global.elesocket.emit('showMessageBoxComplete' + guid, [response, checkboxChecked]); }); } else { var message = browserWindow; var id_1 = guid || options; electron_1.dialog.showMessageBox(browserWindow, function (response, checkboxChecked) { - socket.emit('showMessageBoxComplete' + id_1, [response, checkboxChecked]); + global.elesocket.emit('showMessageBoxComplete' + id_1, [response, checkboxChecked]); }); } }); socket.on('showOpenDialog', function (browserWindow, options, guid) { var window = electron_1.BrowserWindow.fromId(browserWindow.id); electron_1.dialog.showOpenDialog(window, options, function (filePaths) { - socket.emit('showOpenDialogComplete' + guid, filePaths || []); + filePaths = filePaths || []; + var encodeFilePaths = []; + filePaths.forEach((item, index) => { + encodeFilePaths.push(encodeURIComponent(item)); + }); + global.elesocket.emit('showOpenDialogComplete' + guid, encodeFilePaths); }); }); socket.on('showSaveDialog', function (browserWindow, options, guid) { var window = electron_1.BrowserWindow.fromId(browserWindow.id); electron_1.dialog.showSaveDialog(window, options, function (filename) { - socket.emit('showSaveDialogComplete' + guid, filename || ''); + filename = encodeURIComponent(filename || ''); + global.elesocket.emit('showSaveDialogComplete' + guid, filename); }); }); socket.on('showErrorBox', function (title, content) { @@ -35,7 +41,7 @@ module.exports = function (socket) { socket.on('showCertificateTrustDialog', function (browserWindow, options, guid) { var window = electron_1.BrowserWindow.fromId(browserWindow.id); electron_1.dialog.showCertificateTrustDialog(window, options, function () { - socket.emit('showCertificateTrustDialogComplete' + guid); + global.elesocket.emit('showCertificateTrustDialogComplete' + guid); }); }); }; diff --git a/ElectronNET.Host/api/globalShortcut.js b/ElectronNET.Host/api/globalShortcut.js index b1f63a5a..bd7aa0bb 100644 --- a/ElectronNET.Host/api/globalShortcut.js +++ b/ElectronNET.Host/api/globalShortcut.js @@ -4,12 +4,12 @@ var electron_1 = require("electron"); module.exports = function (socket) { socket.on('globalShortcut-register', function (accelerator) { electron_1.globalShortcut.register(accelerator, function () { - socket.emit('globalShortcut-pressed', accelerator); + global.elesocket.emit('globalShortcut-pressed', accelerator); }); }); socket.on('globalShortcut-isRegistered', function (accelerator) { var isRegistered = electron_1.globalShortcut.isRegistered(accelerator); - socket.emit('globalShortcut-isRegisteredCompleted', isRegistered); + global.elesocket.emit('globalShortcut-isRegisteredCompleted', isRegistered); }); socket.on('globalShortcut-unregister', function (accelerator) { electron_1.globalShortcut.unregister(accelerator); diff --git a/ElectronNET.Host/api/ipc.js b/ElectronNET.Host/api/ipc.js index 8bb0fa53..96549829 100644 --- a/ElectronNET.Host/api/ipc.js +++ b/ElectronNET.Host/api/ipc.js @@ -2,24 +2,25 @@ exports.__esModule = true; var electron_1 = require("electron"); module.exports = function (socket) { - socket.on('registerIpcMainChannel', function (channel) { - electron_1.ipcMain.on(channel, function (event, args) { - socket.emit(channel, [event.preventDefault(), args]); + socket.on('registerIpcMainChannel', function (channel) { // ע + electron_1.ipcMain.removeAllListeners(channel); // yf add ֹظ + electron_1.ipcMain.on(channel, function (event, args) { // ǰ˵ + global.elesocket.emit(channel, [event.preventDefault(), args]); // ͵ }); }); socket.on('registerSyncIpcMainChannel', function (channel) { electron_1.ipcMain.on(channel, function (event, args) { - var x = socket; + var x = global.elesocket; x.removeAllListeners(channel + 'Sync'); - socket.on(channel + 'Sync', function (result) { + global.elesocket.on(channel + 'Sync', function (result) { event.returnValue = result; }); - socket.emit(channel, [event.preventDefault(), args]); + global.elesocket.emit(channel, [event.preventDefault(), args]); }); }); socket.on('registerOnceIpcMainChannel', function (channel) { electron_1.ipcMain.once(channel, function (event, args) { - socket.emit(channel, [event.preventDefault(), args]); + global.elesocket.emit(channel, [event.preventDefault(), args]); }); }); socket.on('removeAllListenersIpcMainChannel', function (channel) { diff --git a/ElectronNET.Host/api/menu.js b/ElectronNET.Host/api/menu.js index cc6a8c94..93680e34 100644 --- a/ElectronNET.Host/api/menu.js +++ b/ElectronNET.Host/api/menu.js @@ -6,7 +6,7 @@ module.exports = function (socket) { socket.on('menu-setContextMenu', function (browserWindowId, menuItems) { var menu = electron_1.Menu.buildFromTemplate(menuItems); addContextMenuItemClickConnector(menu.items, browserWindowId, function (id, browserWindowId) { - socket.emit("contextMenuItemClicked", [id, browserWindowId]); + global.elesocket.emit("contextMenuItemClicked", [id, browserWindowId]); }); contextMenuItems.push({ menu: menu, @@ -34,7 +34,7 @@ module.exports = function (socket) { socket.on('menu-setApplicationMenu', function (menuItems) { var menu = electron_1.Menu.buildFromTemplate(menuItems); addMenuItemClickConnector(menu.items, function (id) { - socket.emit("menuItemClicked", id); + global.elesocket.emit("menuItemClicked", id); }); electron_1.Menu.setApplicationMenu(menu); }); diff --git a/ElectronNET.Host/api/notification.js b/ElectronNET.Host/api/notification.js index 020a1535..f4e6b15c 100644 --- a/ElectronNET.Host/api/notification.js +++ b/ElectronNET.Host/api/notification.js @@ -9,31 +9,31 @@ module.exports = function (socket) { if (options.showID) { haveEvent = true; notification.on('show', function () { - socket.emit('NotificationEventShow', options.showID); + global.elesocket.emit('NotificationEventShow', options.showID); }); } if (options.clickID) { haveEvent = true; notification.on('click', function () { - socket.emit('NotificationEventClick', options.clickID); + global.elesocket.emit('NotificationEventClick', options.clickID); }); } if (options.closeID) { haveEvent = true; notification.on('close', function () { - socket.emit('NotificationEventClose', options.closeID); + global.elesocket.emit('NotificationEventClose', options.closeID); }); } if (options.replyID) { haveEvent = true; notification.on('reply', function (event, value) { - socket.emit('NotificationEventReply', [options.replyID, value]); + global.elesocket.emit('NotificationEventReply', [options.replyID, value]); }); } if (options.actionID) { haveEvent = true; notification.on('action', function (event, value) { - socket.emit('NotificationEventAction', [options.actionID, value]); + global.elesocket.emit('NotificationEventAction', [options.actionID, value]); }); } if (haveEvent) { @@ -43,7 +43,7 @@ module.exports = function (socket) { }); socket.on('notificationIsSupported', function (options) { var isSupported = electron_1.Notification.isSupported; - socket.emit('notificationIsSupportedComplete', isSupported); + global.elesocket.emit('notificationIsSupportedComplete', isSupported); }); }; //# sourceMappingURL=notification.js.map \ No newline at end of file diff --git a/ElectronNET.Host/api/screen.js b/ElectronNET.Host/api/screen.js index dee3ea84..440c4d87 100644 --- a/ElectronNET.Host/api/screen.js +++ b/ElectronNET.Host/api/screen.js @@ -4,42 +4,42 @@ var electron_1 = require("electron"); module.exports = function (socket) { socket.on('register-screen-display-added', function (id) { electron_1.screen.on('display-added', function (event, display) { - socket.emit('screen-display-added-event' + id, display); + global.elesocket.emit('screen-display-added-event' + id, display); }); }); socket.on('register-screen-display-removed', function (id) { electron_1.screen.on('display-removed', function (event, display) { - socket.emit('screen-display-removed-event' + id, display); + global.elesocket.emit('screen-display-removed-event' + id, display); }); }); socket.on('register-screen-display-metrics-changed', function (id) { electron_1.screen.on('display-metrics-changed', function (event, display, changedMetrics) { - socket.emit('screen-display-metrics-changed-event' + id, [display, changedMetrics]); + global.elesocket.emit('screen-display-metrics-changed-event' + id, [display, changedMetrics]); }); }); socket.on('screen-getCursorScreenPoint', function () { var point = electron_1.screen.getCursorScreenPoint(); - socket.emit('screen-getCursorScreenPointCompleted', point); + global.elesocket.emit('screen-getCursorScreenPointCompleted', point); }); socket.on('screen-getMenuBarHeight', function () { var height = electron_1.screen.getMenuBarHeight(); - socket.emit('screen-getMenuBarHeightCompleted', height); + global.elesocket.emit('screen-getMenuBarHeightCompleted', height); }); socket.on('screen-getPrimaryDisplay', function () { var display = electron_1.screen.getPrimaryDisplay(); - socket.emit('screen-getPrimaryDisplayCompleted', display); + global.elesocket.emit('screen-getPrimaryDisplayCompleted', display); }); socket.on('screen-getAllDisplays', function () { var display = electron_1.screen.getAllDisplays(); - socket.emit('screen-getAllDisplaysCompleted', display); + global.elesocket.emit('screen-getAllDisplaysCompleted', display); }); socket.on('screen-getDisplayNearestPoint', function (point) { var display = electron_1.screen.getDisplayNearestPoint(point); - socket.emit('screen-getDisplayNearestPointCompleted', display); + global.elesocket.emit('screen-getDisplayNearestPointCompleted', display); }); socket.on('screen-getDisplayMatching', function (rectangle) { var display = electron_1.screen.getDisplayMatching(rectangle); - socket.emit('screen-getDisplayMatchingCompleted', display); + global.elesocket.emit('screen-getDisplayMatchingCompleted', display); }); }; //# sourceMappingURL=screen.js.map \ No newline at end of file diff --git a/ElectronNET.Host/api/shell.js b/ElectronNET.Host/api/shell.js index e88c11b0..6191c96b 100644 --- a/ElectronNET.Host/api/shell.js +++ b/ElectronNET.Host/api/shell.js @@ -4,17 +4,17 @@ var electron_1 = require("electron"); module.exports = function (socket) { socket.on('shell-showItemInFolder', function (fullPath) { var success = electron_1.shell.showItemInFolder(fullPath); - socket.emit('shell-showItemInFolderCompleted', success); + global.elesocket.emit('shell-showItemInFolderCompleted', success); }); socket.on('shell-openItem', function (fullPath) { var success = electron_1.shell.openItem(fullPath); - socket.emit('shell-openItemCompleted', success); + global.elesocket.emit('shell-openItemCompleted', success); }); socket.on('shell-openExternal', function (url, options, callback) { var success = false; if (options && callback) { success = electron_1.shell.openExternal(url, options, function (error) { - socket.emit('shell-openExternalCallback', [url, error]); + global.elesocket.emit('shell-openExternalCallback', [url, error]); }); } else if (options) { @@ -23,22 +23,22 @@ module.exports = function (socket) { else { success = electron_1.shell.openExternal(url); } - socket.emit('shell-openExternalCompleted', success); + global.elesocket.emit('shell-openExternalCompleted', success); }); socket.on('shell-moveItemToTrash', function (fullPath) { var success = electron_1.shell.moveItemToTrash(fullPath); - socket.emit('shell-moveItemToTrashCompleted', success); + global.elesocket.emit('shell-moveItemToTrashCompleted', success); }); socket.on('shell-beep', function () { electron_1.shell.beep(); }); socket.on('shell-writeShortcutLink', function (shortcutPath, operation, options) { var success = electron_1.shell.writeShortcutLink(shortcutPath, operation, options); - socket.emit('shell-writeShortcutLinkCompleted', success); + global.elesocket.emit('shell-writeShortcutLinkCompleted', success); }); socket.on('shell-readShortcutLink', function (shortcutPath) { var shortcutDetails = electron_1.shell.readShortcutLink(shortcutPath); - socket.emit('shell-readShortcutLinkCompleted', shortcutDetails); + global.elesocket.emit('shell-readShortcutLinkCompleted', shortcutDetails); }); }; //# sourceMappingURL=shell.js.map \ No newline at end of file diff --git a/ElectronNET.Host/api/tray.js b/ElectronNET.Host/api/tray.js index 26da2fec..ec729d4e 100644 --- a/ElectronNET.Host/api/tray.js +++ b/ElectronNET.Host/api/tray.js @@ -7,49 +7,49 @@ module.exports = function (socket) { socket.on('register-tray-click', function (id) { if (tray) { tray.on('click', function (event, bounds) { - socket.emit('tray-click-event' + id, [event.__proto__, bounds]); + global.elesocket.emit('tray-click-event' + id, [event.__proto__, bounds]); }); } }); socket.on('register-tray-right-click', function (id) { if (tray) { tray.on('right-click', function (event, bounds) { - socket.emit('tray-right-click-event' + id, [event.__proto__, bounds]); + global.elesocket.emit('tray-right-click-event' + id, [event.__proto__, bounds]); }); } }); socket.on('register-tray-double-click', function (id) { if (tray) { tray.on('double-click', function (event, bounds) { - socket.emit('tray-double-click-event' + id, [event.__proto__, bounds]); + global.elesocket.emit('tray-double-click-event' + id, [event.__proto__, bounds]); }); } }); socket.on('register-tray-balloon-show', function (id) { if (tray) { tray.on('balloon-show', function () { - socket.emit('tray-balloon-show-event' + id); + global.elesocket.emit('tray-balloon-show-event' + id); }); } }); socket.on('register-tray-balloon-click', function (id) { if (tray) { tray.on('balloon-click', function () { - socket.emit('tray-balloon-click-event' + id); + global.elesocket.emit('tray-balloon-click-event' + id); }); } }); socket.on('register-tray-balloon-closed', function (id) { if (tray) { tray.on('balloon-closed', function () { - socket.emit('tray-balloon-closed-event' + id); + global.elesocket.emit('tray-balloon-closed-event' + id); }); } }); socket.on('create-tray', function (image, menuItems) { var menu = electron_1.Menu.buildFromTemplate(menuItems); addMenuItemClickConnector(menu.items, function (id) { - socket.emit("trayMenuItemClicked", id); + global.elesocket.emit("trayMenuItemClicked", id); }); var imagePath = path.join(__dirname.replace('api', ''), 'bin', image); tray = new electron_1.Tray(imagePath); @@ -94,7 +94,7 @@ module.exports = function (socket) { socket.on('tray-isDestroyed', function () { if (tray) { var isDestroyed = tray.isDestroyed(); - socket.emit('tray-isDestroyedCompleted', isDestroyed); + global.elesocket.emit('tray-isDestroyedCompleted', isDestroyed); } }); function addMenuItemClickConnector(menuItems, callback) { diff --git a/ElectronNET.Host/api/webContents.js b/ElectronNET.Host/api/webContents.js index 4a107b0c..55bf478c 100644 --- a/ElectronNET.Host/api/webContents.js +++ b/ElectronNET.Host/api/webContents.js @@ -7,14 +7,14 @@ module.exports = function (socket) { var browserWindow = getWindowById(id); browserWindow.webContents.removeAllListeners('crashed'); browserWindow.webContents.on('crashed', function (event, killed) { - socket.emit('webContents-crashed' + id, killed); + global.elesocket.emit('webContents-crashed' + id, killed); }); }); socket.on('register-webContents-didFinishLoad', function (id) { var browserWindow = getWindowById(id); browserWindow.webContents.removeAllListeners('did-finish-load'); browserWindow.webContents.on('did-finish-load', function () { - socket.emit('webContents-didFinishLoad' + id); + global.elesocket.emit('webContents-didFinishLoad' + id); }); }); socket.on('webContentsOpenDevTools', function (id, options) { @@ -32,10 +32,10 @@ module.exports = function (socket) { } fs.writeFile(path, data, function (error) { if (error) { - socket.emit('webContents-printToPDF-completed', false); + global.elesocket.emit('webContents-printToPDF-completed', false); } else { - socket.emit('webContents-printToPDF-completed', true); + global.elesocket.emit('webContents-printToPDF-completed', true); } }); }); diff --git a/ElectronNET.Host/main.js b/ElectronNET.Host/main.js index ee7c9c42..b3d85501 100644 --- a/ElectronNET.Host/main.js +++ b/ElectronNET.Host/main.js @@ -1,13 +1,37 @@ -const { app } = require('electron'); +const { app } = require('electron'); +// yf add +const { BrowserWindow, dialog, shell } = require('electron') + const fs = require('fs'); const path = require('path'); const process = require('child_process').spawn; const portfinder = require('detect-port'); let io, browserWindows, ipc, apiProcess, loadURL; -let appApi, menu, dialog, notification, tray, webContents; -let globalShortcut, shell, screen, clipboard; +let appApi, menu, dialogApi, notification, tray, webContents; +let globalShortcut, shellApi, screen, clipboard; + +// yf add +let loadingWindow; +let mainWindowId; +let countDownInterval; + +// yf add +const manifestJsonFile = require("./bin/electron.manifest.json"); +if (manifestJsonFile.singleInstance) { + const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => { + mainWindowId && BrowserWindow.fromId(mainWindowId) && BrowserWindow.fromId(mainWindowId).show(); + }); + if (shouldQuit) { + app.quit(); + return; + } +} app.on('ready', () => { + + // yf add + startLoadingWindow(); + portfinder(8000, (error, port) => { startSocketApiBridge(port); }); @@ -15,21 +39,26 @@ app.on('ready', () => { function startSocketApiBridge(port) { io = require('socket.io')(port); + + // yf add startAspCoreBackend(port); io.on('connection', (socket) => { - console.log('ASP.NET Core Application connected...'); - + + global.elesocket = socket; + global.elesocket.setMaxListeners(0); + console.log('ASP.NET Core Application connected...', 'global.elesocket', global.elesocket.id, new Date()); + appApi = require('./api/app')(socket, app); browserWindows = require('./api/browserWindows')(socket); - ipc = require('./api/ipc')(socket); + ipc = require('./api/ipc')(socket); menu = require('./api/menu')(socket); - dialog = require('./api/dialog')(socket); + dialogApi = require('./api/dialog')(socket); notification = require('./api/notification')(socket); tray = require('./api/tray')(socket); webContents = require('./api/webContents')(socket); globalShortcut = require('./api/globalShortcut')(socket); - shell = require('./api/shell')(socket); + shellApi = require('./api/shell')(socket); screen = require('./api/screen')(socket); clipboard = require('./api/clipboard')(socket); }); @@ -42,22 +71,89 @@ function startAspCoreBackend(electronPort) { const manifestFile = require("./bin/electron.manifest.json"); let binaryFile = manifestFile.executable; - + const os = require("os"); - if(os.platform() === "win32") { + if (os.platform() === "win32") { binaryFile = binaryFile + '.exe'; } - + const binFilePath = path.join(__dirname, 'bin', binaryFile); apiProcess = process(binFilePath, parameters); apiProcess.stdout.on('data', (data) => { var text = data.toString(); console.log(`stdout: ${data.toString()}`); + + // yf add + if (text.indexOf(manifestFile.mainWindowShowed) > -1 && + loadingWindow && !loadingWindow.isDestroyed()) { + loadingWindow.close(); + + mainWindowId = parseInt(text.replace(`${manifestFile.mainWindowShowed}:`, "").trim()); + } }); }); } +// yf add +function startLoadingWindow() { + let loadingUrl = manifestJsonFile.loadingUrl; + let icon = manifestJsonFile.icon; + if (loadingUrl) { + loadingWindow = new BrowserWindow({ + width: manifestJsonFile.width, + height: manifestJsonFile.height, + transparent: true, + frame: false, + show: false, + devTools: true, + icon: path.join(__dirname, icon) + }) + if (manifestJsonFile.devTools) { + loadingWindow.webContents.openDevTools(); + } + loadingWindow.loadURL(loadingUrl); + loadingWindow.once('ready-to-show', () => { + loadingWindow.show() + + // 激活倒计时 + activeCountDowInterval(manifestJsonFile) + }) + loadingWindow.on('closed', () => { + loadingWindow = null + + clearInterval(countDownInterval) + }) + } +} + +function activeCountDowInterval(manifestJsonFile) { + if (!manifestJsonFile.timeout || !manifestJsonFile.timeout.limit) + return + + let limitSecond = manifestJsonFile.timeout.limit + let currentSecond = 0; + countDownInterval = setInterval(() => { + currentSecond++; + if (currentSecond < limitSecond) + return; + + clearInterval(countDownInterval); + + dialog.showMessageBox(loadingWindow, { + type: manifestJsonFile.timeout.messageBox.type || 'error', + buttons: manifestJsonFile.timeout.messageBox.buttons || ["前往安装"], + title: manifestJsonFile.timeout.messageBox.title || '文件缺失提示', + message: manifestJsonFile.timeout.messageBox.message || '计算机缺少组件无法启动该程序,点击前往安装组件后重试', + }, (res, isChecked) => { + if (manifestJsonFile.timeout.help) + shell.openExternal(manifestJsonFile.timeout.help) + app.quit(); + }); + + }, 1000) +} + //app.on('activate', () => { // On macOS it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open.