diff --git a/src/features/appMenu/index.js b/src/features/appMenu/index.js index dec5d5de9..d1f106f93 100644 --- a/src/features/appMenu/index.js +++ b/src/features/appMenu/index.js @@ -1,14 +1,14 @@ -import React, { Component } from 'react'; -import { PropTypes } from 'prop-types'; +import { mdiDotsVertical } from '@mdi/js'; +import { Icon } from '@meetfranz/ui'; import { inject, observer } from 'mobx-react'; +import { PropTypes } from 'prop-types'; +import React, { Component } from 'react'; import { intlShape } from 'react-intl'; import injectSheet from 'react-jss'; -import { Icon } from '@meetfranz/ui'; -import { mdiDotsVertical } from '@mdi/js'; -import { windowsTitleBarHeight } from '../../theme/default/legacy'; import { AppMenu } from '../../lib/Menu'; import AppStore from '../../stores/AppStore'; import SettingsStore from '../../stores/SettingsStore'; +import { windowsTitleBarHeight } from '../../theme/default/legacy'; export const APP_MENU_ACKNOWLEDGED_KEY = 'appMenuBarAcknowledged'; diff --git a/src/ipcChannels.ts b/src/ipcChannels.ts index f24c5da8e..d476bc3b5 100644 --- a/src/ipcChannels.ts +++ b/src/ipcChannels.ts @@ -50,7 +50,6 @@ export const WORKSPACE_OPEN_SETTINGS = 'WORKSPACE_OPEN_SETTINGS'; export const WORKSPACE_ACTIVATE = 'WORKSPACE_ACTIVATE'; // General -export const CHECK_FOR_UPDATE = 'CHECK_FOR_UPDATE'; export const FETCH_DEBUG_INFO = 'FETCH_DEBUG_INFO'; export const TOGGLE_FULL_SCREEN = 'TOGGLE_FULL_SCREEN'; export const CHECK_MACOS_PERMISSIONS = 'CHECK_MACOS_PERMISSIONS'; diff --git a/src/lib/Menu.js b/src/lib/Menu.js index b630d9042..c3456ab28 100644 --- a/src/lib/Menu.js +++ b/src/lib/Menu.js @@ -1,23 +1,28 @@ -import { shell, clipboard, ipcRenderer } from 'electron'; import { - app, Menu, dialog, webContents, getCurrentWindow, + app, + dialog, + getCurrentWindow, + Menu, + webContents, } from '@electron/remote'; -import { observable, autorun } from 'mobx'; +import { clipboard, ipcRenderer, shell } from 'electron'; +import { autorun, observable } from 'mobx'; import { defineMessages } from 'react-intl'; -import { isMac, ctrlKey, cmdKey } from '../environment'; -import { GA_CATEGORY_WORKSPACES, workspaceStore } from '../features/workspaces/index'; -import { workspaceActions } from '../features/workspaces/actions'; -import { gaEvent } from './analytics'; -import { announcementActions } from '../features/announcements/actions'; +import { DEFAULT_WEB_CONTENTS_ID } from '../config'; +import { cmdKey, ctrlKey, isMac } from '../environment'; import { announcementsStore } from '../features/announcements'; +import { announcementActions } from '../features/announcements/actions'; import { GA_CATEGORY_TODOS, todosStore } from '../features/todos'; import { todoActions } from '../features/todos/actions'; import { CUSTOM_WEBSITE_ID } from '../features/webControls/constants'; +import { workspaceActions } from '../features/workspaces/actions'; +import { GA_CATEGORY_WORKSPACES, workspaceStore } from '../features/workspaces/index'; import { - ACTIVATE_NEXT_SERVICE, ACTIVATE_PREVIOUS_SERVICE, ACTIVATE_SERVICE, CHECK_FOR_UPDATE, FETCH_DEBUG_INFO, GET_ACTIVE_SERVICE_WEB_CONTENTS_ID, OPEN_SERVICE_DEV_TOOLS, RELOAD_APP, RELOAD_SERVICE, SETTINGS_NAVIGATE_TO, TODOS_OPEN_DEV_TOOLS, TODOS_RELOAD, TODOS_TOGGLE_DRAWER, TODOS_TOGGLE_ENABLE_TODOS, TOGGLE_FULL_SCREEN, WORKSPACE_ACTIVATE, WORKSPACE_OPEN_SETTINGS, WORKSPACE_TOGGLE_DRAWER, + ACTIVATE_NEXT_SERVICE, ACTIVATE_PREVIOUS_SERVICE, ACTIVATE_SERVICE, + GET_ACTIVE_SERVICE_WEB_CONTENTS_ID, OPEN_SERVICE_DEV_TOOLS, RELOAD_APP, RELOAD_SERVICE, SETTINGS_NAVIGATE_TO, TODOS_OPEN_DEV_TOOLS, TODOS_RELOAD, TODOS_TOGGLE_DRAWER, TODOS_TOGGLE_ENABLE_TODOS, TOGGLE_FULL_SCREEN, WORKSPACE_ACTIVATE, WORKSPACE_OPEN_SETTINGS, WORKSPACE_TOGGLE_DRAWER, } from '../ipcChannels'; -import { DEFAULT_WEB_CONTENTS_ID } from '../config'; +import { gaEvent } from './analytics'; export const menuItems = defineMessages({ edit: { @@ -452,7 +457,7 @@ export const _titleBarTemplateFactory = ({ user, intl }) => [ label: intl.formatMessage(menuItems.reloadFranz), accelerator: `${cmdKey}+Shift+R`, click: () => { - ipcRenderer.sendTo(DEFAULT_WEB_CONTENTS_ID, RELOAD_APP); + window.location.reload(); }, }, { @@ -493,7 +498,7 @@ export const _titleBarTemplateFactory = ({ user, intl }) => [ }, { label: intl.formatMessage(menuItems.changelog), - click() { shell.openExternal('https://github.com/meetfranz/franz/blob/master/CHANGELOG.md'); }, + click() { shell.openExternal('https://meetfranz.com/changelog'); }, }, { type: 'separator', @@ -519,17 +524,14 @@ export const _titleBarTemplateFactory = ({ user, intl }) => [ { label: intl.formatMessage(menuItems.debugInfo), click: () => { - ipcRenderer.on(FETCH_DEBUG_INFO, (e, data) => { - console.log('huhu, debug'); - clipboard.write({ - text: JSON.stringify(data), - }); + const { debugInfo } = window.franz.stores.app; + clipboard.write({ + text: JSON.stringify(debugInfo, null, 2), + }); - const notification = new window.Notification(intl.formatMessage(menuItems.debugInfoCopiedHeadline), { - body: intl.formatMessage(menuItems.debugInfoCopiedBody), - }); + const notification = new window.Notification(intl.formatMessage(menuItems.debugInfoCopiedHeadline), { + body: intl.formatMessage(menuItems.debugInfoCopiedBody), }); - ipcRenderer.sendTo(DEFAULT_WEB_CONTENTS_ID, FETCH_DEBUG_INFO); }, }, ], @@ -557,7 +559,7 @@ export const _titleBarTemplateFactory = ({ user, intl }) => [ { label: intl.formatMessage(menuItems.checkForUpdates), click: () => { - ipcRenderer.sendTo(DEFAULT_WEB_CONTENTS_ID, CHECK_FOR_UPDATE); + window.franz.actions.app.checkForUpdates(); }, }, { @@ -567,18 +569,13 @@ export const _titleBarTemplateFactory = ({ user, intl }) => [ label: intl.formatMessage(menuItems.settings), accelerator: 'CmdOrCtrl+,', click: () => { - ipcRenderer.sendTo(DEFAULT_WEB_CONTENTS_ID, SETTINGS_NAVIGATE_TO, { - path: 'app', - }); + window.franz.actions.ui.openSettings({ path: 'app' }); }, enabled: user.isLoggedIn, }, { type: 'separator', }, - { - type: 'separator', - }, { label: intl.formatMessage(menuItems.edit), visible: false, @@ -785,7 +782,8 @@ function serviceMenu({ && services.length > 0) { ipcRenderer.send(RELOAD_SERVICE); } else { - ipcRenderer.sendTo(DEFAULT_WEB_CONTENTS_ID, RELOAD_APP); + const contents = webContents.fromId(DEFAULT_WEB_CONTENTS_ID); + contents.send(RELOAD_APP); } }, }); @@ -819,7 +817,8 @@ function workspacesMenu({ label: intl.formatMessage(menuItems.addNewWorkspace), accelerator: `${cmdKey}+Shift+N`, click: () => { - ipcRenderer.sendTo(DEFAULT_WEB_CONTENTS_ID, WORKSPACE_OPEN_SETTINGS); + const contents = webContents.fromId(DEFAULT_WEB_CONTENTS_ID); + contents.send(WORKSPACE_OPEN_SETTINGS); }, enabled: user.isLoggedIn, }); @@ -832,7 +831,8 @@ function workspacesMenu({ label: intl.formatMessage(drawerLabel), accelerator: `${cmdKey}+D`, click: () => { - ipcRenderer.sendTo(DEFAULT_WEB_CONTENTS_ID, WORKSPACE_TOGGLE_DRAWER); + const contents = webContents.fromId(DEFAULT_WEB_CONTENTS_ID); + contents.send(WORKSPACE_TOGGLE_DRAWER); gaEvent(GA_CATEGORY_WORKSPACES, 'toggleDrawer', 'menu'); }, enabled: user.isLoggedIn, @@ -847,7 +847,8 @@ function workspacesMenu({ type: 'radio', checked: !activeWorkspace, click: () => { - ipcRenderer.sendTo(DEFAULT_WEB_CONTENTS_ID, WORKSPACE_ACTIVATE); + const contents = webContents.fromId(DEFAULT_WEB_CONTENTS_ID); + contents.send(WORKSPACE_ACTIVATE); gaEvent(GA_CATEGORY_WORKSPACES, 'switch', 'menu'); }, }); @@ -860,7 +861,8 @@ function workspacesMenu({ type: 'radio', checked: activeWorkspace ? workspace.id === activeWorkspace.id : false, click: () => { - ipcRenderer.sendTo(DEFAULT_WEB_CONTENTS_ID, WORKSPACE_ACTIVATE, { workspaceId: workspace.id }); + const contents = webContents.fromId(DEFAULT_WEB_CONTENTS_ID); + contents.send(WORKSPACE_ACTIVATE, { workspaceId: workspace.id }); gaEvent(GA_CATEGORY_WORKSPACES, 'switch', 'menu'); }, })); @@ -880,7 +882,9 @@ function todosMenu({ label: intl.formatMessage(drawerLabel), accelerator: `${cmdKey}+T`, click: () => { - ipcRenderer.sendTo(DEFAULT_WEB_CONTENTS_ID, TODOS_TOGGLE_DRAWER); + const contents = webContents.fromId(DEFAULT_WEB_CONTENTS_ID); + contents.send(TODOS_TOGGLE_DRAWER); + gaEvent(GA_CATEGORY_TODOS, 'toggleDrawer', 'menu'); }, enabled: user.isLoggedIn && isTodosEnabled, @@ -908,7 +912,8 @@ function todosMenu({ }, { label: intl.formatMessage(menuItems.enableTodos), click: () => { - ipcRenderer.sendTo(DEFAULT_WEB_CONTENTS_ID, TODOS_TOGGLE_ENABLE_TODOS); + const contents = webContents.fromId(DEFAULT_WEB_CONTENTS_ID); + contents.send(TODOS_TOGGLE_ENABLE_TODOS); gaEvent(GA_CATEGORY_TODOS, 'enable', 'menu'); }, }); diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index aa674e04f..83e8edc07 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js @@ -30,7 +30,7 @@ import { sleep } from '../helpers/async-helpers'; import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; import { isValidExternalURL } from '../helpers/url-helpers'; import { - CHECK_FOR_UPDATE, CHECK_MACOS_PERMISSIONS, FETCH_DEBUG_INFO, OVERLAY_SHARE_SETTINGS, RELOAD_APP, WINDOWS_TITLEBAR_FETCH_MENU, + CHECK_MACOS_PERMISSIONS, FETCH_DEBUG_INFO, OVERLAY_SHARE_SETTINGS, RELOAD_APP, WINDOWS_TITLEBAR_FETCH_MENU } from '../ipcChannels'; const debug = require('debug')('Franz:AppStore'); @@ -180,10 +180,6 @@ export default class AppStore extends Store { ipcRenderer.sendTo(e.senderId, FETCH_DEBUG_INFO, JSON.parse(JSON.stringify(this.debugInfo))); }); - ipcRenderer.on(CHECK_FOR_UPDATE, () => { - this._checkForUpdates(); - }); - // Handle deep linking (franz://) ipcRenderer.on('navigateFromDeepLink', (event, data) => { debug('Navigate from deep link', data);