Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix theme menu state on mac #1280

Merged
merged 6 commits into from
Feb 1, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
- [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).
12 changes: 9 additions & 3 deletions packages/app/main/src/appMenuBuilder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -308,7 +308,7 @@ describe('AppMenuBuilder', () => {
},
};
mockRemoteCall = jest.fn(commandName => {
if ((commandName = SharedConstants.Commands.Misc.GetStoreState)) {
if (commandName === SharedConstants.Commands.Misc.GetStoreState) {
a-b-r-o-w-n marked this conversation as resolved.
Show resolved Hide resolved
return Promise.resolve(mockState);
} else {
return Promise.resolve({});
Expand All @@ -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);

Expand Down Expand Up @@ -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({});
Expand All @@ -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');
});
});
5 changes: 3 additions & 2 deletions packages/app/main/src/appMenuBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion packages/app/main/src/commands/botCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions packages/app/main/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/app/main/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
55 changes: 55 additions & 0 deletions packages/app/main/src/utils/platform.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
36 changes: 36 additions & 0 deletions packages/app/main/src/utils/platform.ts
Original file line number Diff line number Diff line change
@@ -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';
}