diff --git a/CHANGELOG.md b/CHANGELOG.md index affddf8c9..c748ab3c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,5 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - [docs] Added changelog in PR [#1230](https://github.com/Microsoft/BotFramework-Emulator/pull/1230) - [style] 💅 Integrated prettier and eslint in PR [#1240](https://github.com/Microsoft/BotFramework-Emulator/pull/1240) -- [feat] Added app-wide instrumentation in PR [#1251](https://github.com/Microsoft/BotFramework-Emulator/pull/1251) -- [fix] Fixed issue [(#1257)](https://github.com/Microsoft/BotFramework-Emulator/issues/1257) where opening transcripts via the command line was crashing the app, in PR [#1269](https://github.com/Microsoft/BotFramework-Emulator/pull/1269). \ No newline at end of file +- [main / client] Added app-wide instrumentation in PR [#1251](https://github.com/Microsoft/BotFramework-Emulator/pull/1251) + +### Fixed +- [main] Fixed issue [(#1257)](https://github.com/Microsoft/BotFramework-Emulator/issues/1257) where opening transcripts via the command line was crashing the app, in PR [#1269](https://github.com/Microsoft/BotFramework-Emulator/pull/1269). +- [main] display correct selected theme in file menu on mac, in PR [#1280](https://github.com/Microsoft/BotFramework-Emulator/pull/1280). diff --git a/packages/app/main/src/appMenuBuilder.spec.ts b/packages/app/main/src/appMenuBuilder.spec.ts index 5df17419d..dee0d240b 100644 --- a/packages/app/main/src/appMenuBuilder.spec.ts +++ b/packages/app/main/src/appMenuBuilder.spec.ts @@ -234,7 +234,7 @@ describe('AppMenuBuilder', () => { }); it('should update the recent bots list', () => { - mockRemoteCall = jest.fn((..._args) => Promise.resolve(null)); + mockRemoteCall = jest.fn(() => Promise.resolve(null)); const mockBotPath = join('path', 'to', 'bot'); const mockRecentBots = [ { displayName: 'bot1', path: mockBotPath }, @@ -308,7 +308,7 @@ describe('AppMenuBuilder', () => { }, }; mockRemoteCall = jest.fn(commandName => { - if ((commandName = SharedConstants.Commands.Misc.GetStoreState)) { + if (commandName === SharedConstants.Commands.Misc.GetStoreState) { return Promise.resolve(mockState); } else { return Promise.resolve({}); @@ -331,6 +331,7 @@ describe('AppMenuBuilder', () => { const themeMenu = fileMenuTemplate[11]; expect(themeMenu.label).toBe('Themes'); expect(themeMenu.submenu).toHaveLength(3); // light, dark, midnight + expect(themeMenu.submenu[2].type).toBe('checkbox'); expect(themeMenu.submenu[2].label).toBe('midnight'); expect(themeMenu.submenu[2].checked).toBe(true); @@ -382,7 +383,7 @@ describe('AppMenuBuilder', () => { }, }; mockRemoteCall = jest.fn(commandName => { - if ((commandName = SharedConstants.Commands.Misc.GetStoreState)) { + if (commandName === SharedConstants.Commands.Misc.GetStoreState) { return Promise.resolve(mockState); } else { return Promise.resolve({}); @@ -399,5 +400,10 @@ describe('AppMenuBuilder', () => { const windowMenuTemplate = appMenuTemplate[4].submenu; expect(windowMenuTemplate).toHaveLength(5); + + // should set the theme menu type to radio + const fileMenuTemplate = appMenuTemplate[1].submenu; + const themeMenu = fileMenuTemplate[11]; + expect(themeMenu.submenu[0].type).toBe('radio'); }); }); diff --git a/packages/app/main/src/appMenuBuilder.ts b/packages/app/main/src/appMenuBuilder.ts index 81bca52fb..ef2b18dcc 100644 --- a/packages/app/main/src/appMenuBuilder.ts +++ b/packages/app/main/src/appMenuBuilder.ts @@ -42,6 +42,7 @@ import { emulator } from './emulator'; import { mainWindow } from './main'; import { rememberTheme } from './settingsData/actions/windowStateActions'; import { getStore as getSettingsStore } from './settingsData/store'; +import { isMac } from './utils'; declare type MenuOpts = Electron.MenuItemConstructorOptions; @@ -76,7 +77,7 @@ export class AppMenuBuilder { await this.initHelpMenu(), ]; - if (process.platform === 'darwin') { + if (isMac()) { template.unshift(await this.initAppMenuMac()); // Window menu template.splice(4, 0, { @@ -246,7 +247,7 @@ export class AppMenuBuilder { label: 'Themes', submenu: availableThemes.map(t => ({ label: t.name, - type: 'checkbox', + type: isMac() ? 'radio' : 'checkbox', checked: theme === t.name, click: async () => { settingsStore.dispatch(rememberTheme(t.name)); diff --git a/packages/app/main/src/commands/botCommands.ts b/packages/app/main/src/commands/botCommands.ts index 101a54dd3..884a981b0 100644 --- a/packages/app/main/src/commands/botCommands.ts +++ b/packages/app/main/src/commands/botCommands.ts @@ -55,6 +55,7 @@ import { emulator } from '../emulator'; import { mainWindow } from '../main'; import { botProjectFileWatcher, chatWatcher, transcriptsWatcher } from '../watchers'; import { TelemetryService } from '../telemetry'; +import { isMac } from '../utils'; /** Registers bot commands */ export function registerCommands(commandRegistry: CommandRegistryImpl) { @@ -174,7 +175,7 @@ export function registerCommands(commandRegistry: CommandRegistryImpl) { const displayedTranscriptsPath = relativeTranscriptsPath.includes('..') ? transcriptsPath : relativeTranscriptsPath; - const sep = process.platform === 'darwin' ? path.posix.sep : (path.posix as any).win32.sep; + const sep = isMac() ? path.posix.sep : (path.posix as any).win32.sep; await Promise.all([ chatWatcher.watch(chatsPath), transcriptsWatcher.watch(transcriptsPath), diff --git a/packages/app/main/src/main.ts b/packages/app/main/src/main.ts index 9391ba2e3..45ad67471 100644 --- a/packages/app/main/src/main.ts +++ b/packages/app/main/src/main.ts @@ -55,7 +55,7 @@ import { Window } from './platform/window'; import { azureLoggedInUserChanged } from './settingsData/actions/azureAuthActions'; import { rememberBounds, rememberTheme } from './settingsData/actions/windowStateActions'; import { dispatch, getSettings, getStore as getSettingsStore } from './settingsData/store'; -import { botListsAreDifferent, ensureStoragePath, saveSettings, writeFile } from './utils'; +import { botListsAreDifferent, ensureStoragePath, saveSettings, writeFile, isMac } from './utils'; import { openFileFromCommandLine } from './utils/openFileFromCommandLine'; import { sendNotificationToClient } from './utils/sendNotificationToClient'; import { WindowManager } from './windowManager'; @@ -220,7 +220,7 @@ ngrokEmitter.on('expired', () => { let openUrls = []; const onOpenUrl = function(event: any, url1: any) { event.preventDefault(); - if (process.platform === 'darwin') { + if (isMac()) { if (mainWindow && mainWindow.webContents) { // the app is already running, send a message containing the url to the renderer process mainWindow.webContents.send('botemulator', url1); diff --git a/packages/app/main/src/utils/index.ts b/packages/app/main/src/utils/index.ts index d73d368f6..c27379931 100644 --- a/packages/app/main/src/utils/index.ts +++ b/packages/app/main/src/utils/index.ts @@ -41,6 +41,7 @@ export * from './getSafeBotName'; export * from './isDev'; export * from './loadSettings'; export * from './parseActivitiesFromChatFile'; +export * from './platform'; export * from './readFileSync'; export * from './saveSettings'; export * from './sendErrorResponse'; diff --git a/packages/app/main/src/utils/platform.spec.ts b/packages/app/main/src/utils/platform.spec.ts new file mode 100644 index 000000000..7c364d94c --- /dev/null +++ b/packages/app/main/src/utils/platform.spec.ts @@ -0,0 +1,55 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. +// +// Microsoft Bot Framework: http://botframework.com +// +// Bot Framework Emulator Github: +// https://github.com/Microsoft/BotFramwork-Emulator +// +// Copyright (c) Microsoft Corporation +// All rights reserved. +// +// MIT License: +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +import { isMac } from './platform'; + +describe('#isMac', () => { + let originalPlatform; + + beforeEach(() => { + originalPlatform = process.platform; + }); + + afterEach(() => { + Object.defineProperty(process, 'platform', { value: originalPlatform }); + }); + + it('returns true when platform is darwin', () => { + Object.defineProperty(process, 'platform', { value: 'darwin' }); + expect(isMac()).toBe(true); + }); + + it('returns false when platform is not darwin', () => { + Object.defineProperty(process, 'platform', { value: 'something-else' }); + expect(isMac()).toBe(false); + }); +}); diff --git a/packages/app/main/src/utils/platform.ts b/packages/app/main/src/utils/platform.ts new file mode 100644 index 000000000..35d772652 --- /dev/null +++ b/packages/app/main/src/utils/platform.ts @@ -0,0 +1,36 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. +// +// Microsoft Bot Framework: http://botframework.com +// +// Bot Framework Emulator Github: +// https://github.com/Microsoft/BotFramwork-Emulator +// +// Copyright (c) Microsoft Corporation +// All rights reserved. +// +// MIT License: +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +export function isMac() { + return process.platform === 'darwin'; +}