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

Disable changelog menu opt if curr ver is not available #373

10 changes: 8 additions & 2 deletions src/auto-updater/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const {
addOnceProcEventHandler
} = require('../window-event-manager')

const MENU_ITEM_IDS = require('../create-menu/menu.item.ids')

const isAutoUpdateDisabled = parseEnvValToBool(process.env.IS_AUTO_UPDATE_DISABLED)

const fontsStyle = fs.readFileSync(path.join(
Expand Down Expand Up @@ -219,8 +221,12 @@ const _switchMenuItem = (opts = {}) => {
isCheckMenuItemDisabled,
isInstallMenuItemVisible
} = { ...opts }
const checkMenuItem = _getUpdateMenuItemById('CHECK_UPDATE_MENU_ITEM')
const installMenuItem = _getUpdateMenuItemById('INSTALL_UPDATE_MENU_ITEM')
const checkMenuItem = _getUpdateMenuItemById(
MENU_ITEM_IDS.CHECK_UPDATE_MENU_ITEM
)
const installMenuItem = _getUpdateMenuItemById(
MENU_ITEM_IDS.INSTALL_UPDATE_MENU_ITEM
)

if (
!checkMenuItem ||
Expand Down
11 changes: 9 additions & 2 deletions src/changelog-manager/manage-changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ module.exports = async () => {
return
}

const isShown = await showChangelog({ version })
const {
error,
isShown
} = await showChangelog({ version })

if (!isShown) {
return
}

const isSaved = await configsKeeper
.saveConfigs({ shownChangelogVer: version })

if (
isSaved &&
isShown
!error
) {
return
}
Expand Down
38 changes: 32 additions & 6 deletions src/changelog-manager/show-changelog.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
'use strict'

const { Menu } = require('electron')
const path = require('path')
const parseChangelog = require('changelog-parser')
const { rootPath } = require('electron-root-path')

const getDebugInfo = require('../helpers/get-debug-info')
const showDocs = require('../show-docs')

const MENU_ITEM_IDS = require('../create-menu/menu.item.ids')

const changelogPath = path.join(rootPath, 'CHANGELOG.md')

const disableShowChangelogMenuItem = () => {
const menuItem = Menu.getApplicationMenu()
?.getMenuItemById(MENU_ITEM_IDS.SHOW_CHANGE_LOG_MENU_ITEM) ?? {}

menuItem.enabled = false
}

module.exports = async (params = {}) => {
try {
const version = params?.version ?? getDebugInfo()?.version
Expand All @@ -23,7 +33,12 @@ module.exports = async (params = {}) => {
!Array.isArray(mdEntries?.versions) ||
mdEntries?.versions.length === 0
) {
return true
disableShowChangelogMenuItem()

return {
error: null,
isShown: false
}
}

const mdEntry = mdEntries.versions
Expand All @@ -33,7 +48,12 @@ module.exports = async (params = {}) => {
!mdEntry?.title ||
!mdEntry?.body
) {
return true
disableShowChangelogMenuItem()

return {
error: null,
isShown: false
}
}

const mdTitle = `# ${mdEntries.title}`
Expand All @@ -45,10 +65,16 @@ module.exports = async (params = {}) => {
mdDoc
})

return true
} catch (err) {
console.error(err)
return {
error: null,
isShown: true
}
} catch (error) {
console.error(error)

return false
return {
error,
isShown: false
}
}
}
37 changes: 20 additions & 17 deletions src/create-menu.js → src/create-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@ const electron = require('electron')
const { app, Menu } = electron
const isMac = process.platform === 'darwin'

const exportDB = require('./export-db')
const importDB = require('./import-db')
const removeDB = require('./remove-db')
const restoreDB = require('./restore-db')
const backupDB = require('./backup-db')
const changeReportsFolder = require('./change-reports-folder')
const changeSyncFrequency = require('./change-sync-frequency')
const triggerElectronLoad = require('./trigger-electron-load')
const showAboutModalDialog = require('./show-about-modal-dialog')
const exportDB = require('../export-db')
const importDB = require('../import-db')
const removeDB = require('../remove-db')
const restoreDB = require('../restore-db')
const backupDB = require('../backup-db')
const changeReportsFolder = require('../change-reports-folder')
const changeSyncFrequency = require('../change-sync-frequency')
const triggerElectronLoad = require('../trigger-electron-load')
const showAboutModalDialog = require('../show-about-modal-dialog')
const {
checkForUpdates,
quitAndInstall
} = require('./auto-updater')
const { manageNewGithubIssue } = require('./error-manager')
const showDocs = require('./show-docs')
const { showChangelog } = require('./changelog-manager')
const parseEnvValToBool = require('./helpers/parse-env-val-to-bool')
} = require('../auto-updater')
const { manageNewGithubIssue } = require('../error-manager')
const showDocs = require('../show-docs')
const { showChangelog } = require('../changelog-manager')
const parseEnvValToBool = require('../helpers/parse-env-val-to-bool')

const MENU_ITEM_IDS = require('./menu.item.ids')

const isAutoUpdateDisabled = parseEnvValToBool(process.env.IS_AUTO_UPDATE_DISABLED)

Expand Down Expand Up @@ -137,20 +139,20 @@ module.exports = ({
submenu: [
{
label: 'Open new GitHub issue',
id: 'REPORT_BUG_MENU_ITEM',
id: MENU_ITEM_IDS.REPORT_BUG_MENU_ITEM,
click: manageNewGithubIssue
},
{ type: 'separator' },
{
label: 'Check for updates',
enabled: !isAutoUpdateDisabled,
id: 'CHECK_UPDATE_MENU_ITEM',
id: MENU_ITEM_IDS.CHECK_UPDATE_MENU_ITEM,
click: checkForUpdates()
},
{
label: 'Quit and install updates',
visible: false,
id: 'INSTALL_UPDATE_MENU_ITEM',
id: MENU_ITEM_IDS.INSTALL_UPDATE_MENU_ITEM,
click: quitAndInstall()
},
{ type: 'separator' },
Expand All @@ -161,6 +163,7 @@ module.exports = ({
},
{
label: 'Changelog',
id: MENU_ITEM_IDS.SHOW_CHANGE_LOG_MENU_ITEM,
click: () => showChangelog()
},
...(isMac
Expand Down
8 changes: 8 additions & 0 deletions src/create-menu/menu.item.ids.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict'

module.exports = {
REPORT_BUG_MENU_ITEM: 'REPORT_BUG_MENU_ITEM',
CHECK_UPDATE_MENU_ITEM: 'CHECK_UPDATE_MENU_ITEM',
INSTALL_UPDATE_MENU_ITEM: 'INSTALL_UPDATE_MENU_ITEM',
SHOW_CHANGE_LOG_MENU_ITEM: 'SHOW_CHANGE_LOG_MENU_ITEM'
}
4 changes: 3 additions & 1 deletion src/error-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const openNewGithubIssue = require('./open-new-github-issue')
const collectLogs = require('./collect-logs')
const getDebugInfo = require('../helpers/get-debug-info')

const MENU_ITEM_IDS = require('../create-menu/menu.item.ids')

let _isLocked = false
let _isIssueAutoManagerLocked = false
let caughtError
Expand Down Expand Up @@ -97,7 +99,7 @@ const _getReportBugMenuItem = () => {
return {}
}

return menu.getMenuItemById('REPORT_BUG_MENU_ITEM') || {}
return menu.getMenuItemById(MENU_ITEM_IDS.REPORT_BUG_MENU_ITEM) || {}
}

const _lockIssueManager = () => {
Expand Down