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: macos dark menu #1022

Merged
merged 2 commits into from
Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 6 additions & 24 deletions src/main/ui/TrayManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Tray, Menu, nativeImage } from 'electron'
import is from 'electron-is'

import { APP_THEME } from '@shared/constants'
import { getInverseTheme, getSystemMajorVersion } from '@shared/utils'
import { getInverseTheme } from '@shared/utils'
import { getI18n } from './Locale'
import {
translateTemplate,
Expand All @@ -26,7 +26,7 @@ export default class TrayManager extends EventEmitter {

this.systemTheme = options.systemTheme
this.inverseSystemTheme = getInverseTheme(this.systemTheme)
this.bigSur = platform === 'darwin' && getSystemMajorVersion() >= 20
this.macOS = platform === 'darwin'

this.speedometer = options.speedometer

Expand Down Expand Up @@ -77,25 +77,7 @@ export default class TrayManager extends EventEmitter {
}

loadImagesForMacOS () {
if (this.bigSur) {
const {
systemTheme,
inverseSystemTheme
} = this

this.normalIcon = this.getFromCacheOrCreateImage(`mo-tray-${systemTheme}-normal.png`)
this.activeIcon = this.getFromCacheOrCreateImage(`mo-tray-${systemTheme}-active.png`)

// if (systemTheme === APP_THEME.DARK) {
// this.inverseNormalIcon = this.normalIcon
// this.inverseActiveIcon = this.activeIcon
// } else {
this.inverseNormalIcon = this.getFromCacheOrCreateImage(`mo-tray-${inverseSystemTheme}-normal.png`)
this.inverseActiveIcon = this.getFromCacheOrCreateImage(`mo-tray-${inverseSystemTheme}-active.png`)
// }
} else {
this.normalIcon = this.getFromCacheOrCreateImage('mo-tray-light-normal.png')
}
this.normalIcon = this.getFromCacheOrCreateImage('mo-tray-light-normal.png')
}

loadImagesForWindows () {
Expand Down Expand Up @@ -126,7 +108,7 @@ export default class TrayManager extends EventEmitter {
}

file = nativeImage.createFromPath(join(__static, `./${key}`))
file.setTemplateImage(this.bigSur)
file.setTemplateImage(this.macOS)
this.setCache(key, file)
return file
}
Expand Down Expand Up @@ -238,7 +220,7 @@ export default class TrayManager extends EventEmitter {
}

getIcons () {
if (this.bigSur) {
if (this.macOS) {
return { icon: this.normalIcon }
}

Expand Down Expand Up @@ -336,7 +318,7 @@ export default class TrayManager extends EventEmitter {
const image = nativeImage.createFromBuffer(buffer, {
scaleFactor: 2
})
image.setTemplateImage(this.bigSur)
image.setTemplateImage(this.macOS)
tray.setImage(image)
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/ui/WindowManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default class WindowManager extends EventEmitter {

showWindow (page) {
const window = this.getWindow(page)
if (!window || window.isVisible()) {
if (!window || (window.isVisible() && !window.isMinimized())) {
return
}

Expand Down
1 change: 0 additions & 1 deletion src/renderer/components/Native/DynamicTray.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
name: 'mo-dynamic-tray',
computed: {
...mapState('app', {
bigSur: state => state.bigSur,
iconStatus: state => state.stat.numActive > 0 ? 'active' : 'normal',
theme: state => state.systemTheme,
focused: state => state.trayFocused,
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/store/modules/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ADD_TASK_TYPE } from '@shared/constants'
import api from '@/api'
import { getSystemTheme, isBigSur } from '@/utils/native'
import { getSystemTheme } from '@/utils/native'

const BASE_INTERVAL = 1000
const PER_INTERVAL = 100
Expand All @@ -9,7 +9,6 @@ const MAX_INTERVAL = 6000

const state = {
systemTheme: getSystemTheme(),
bigSur: isBigSur(),
trayFocused: false,
aboutPanelVisible: false,
engineInfo: {
Expand Down
7 changes: 1 addition & 6 deletions src/renderer/utils/native.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { Message } from 'element-ui'

import {
getFileNameFromFile,
isMagnetTask,
getSystemMajorVersion
isMagnetTask
} from '@shared/utils'
import { APP_THEME, TASK_STATUS } from '@shared/constants'

Expand Down Expand Up @@ -123,10 +122,6 @@ export function getSystemTheme () {
return result
}

export function isBigSur () {
return is.macOS() && getSystemMajorVersion() >= 20
}

export const delayDeleteTaskFiles = (task, delay) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
Expand Down
5 changes: 0 additions & 5 deletions src/shared/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,3 @@ export const intersection = (array1 = [], array2 = []) => {
export const getInverseTheme = (theme) => {
return (theme === APP_THEME.LIGHT) ? APP_THEME.DARK : APP_THEME.LIGHT
}

export const getSystemMajorVersion = () => {
const version = require('os').release()
return parseInt(version.substr(0, version.indexOf('.')))
}