diff --git a/public/menubar-newdarwin.png b/public/menubar-newdarwin.png index 168f2ad..32fdd96 100644 Binary files a/public/menubar-newdarwin.png and b/public/menubar-newdarwin.png differ diff --git a/public/menubar-newdarwin@2.png b/public/menubar-newdarwin@2.png new file mode 100644 index 0000000..d260146 Binary files /dev/null and b/public/menubar-newdarwin@2.png differ diff --git a/public/menubar-newdarwin@3.png b/public/menubar-newdarwin@3.png new file mode 100644 index 0000000..189a332 Binary files /dev/null and b/public/menubar-newdarwin@3.png differ diff --git a/src/main/apis/app/system/index.ts b/src/main/apis/app/system/index.ts index f787aeb..4ea52fd 100644 --- a/src/main/apis/app/system/index.ts +++ b/src/main/apis/app/system/index.ts @@ -18,6 +18,7 @@ import pkg from 'root/package.json' import { handleCopyUrl } from '~/main/utils/common' import { privacyManager } from '~/main/utils/privacyManager' import { T } from '#/i18n' +import { isMacOSVersionGreaterThanOrEqualTo } from '~/main/utils/getMacOSVersion' let contextMenu: Menu | null let menu: Menu | null let tray: Tray | null @@ -147,8 +148,17 @@ export function createContextMenu () { } } +const getTrayIcon = () => { + if (process.platform === 'darwin') { + const isMacOSGreaterThan11 = isMacOSVersionGreaterThanOrEqualTo('11') + return isMacOSGreaterThan11 ? `${__static}/menubar-newdarwin.png` : `${__static}/menubar.png` + } else { + return `${__static}/menubar-nodarwin.png` + } +} + export function createTray () { - const menubarPic = process.platform === 'darwin' ? `${__static}/menubar.png` : `${__static}/menubar-nodarwin.png` + const menubarPic = getTrayIcon() tray = new Tray(menubarPic) // click事件在Mac和Windows上可以触发(在Ubuntu上无法触发,Unity不支持) if (process.platform === 'darwin' || process.platform === 'win32') { diff --git a/src/main/utils/getMacOSVersion.ts b/src/main/utils/getMacOSVersion.ts new file mode 100644 index 0000000..b0d35cb --- /dev/null +++ b/src/main/utils/getMacOSVersion.ts @@ -0,0 +1,97 @@ +// fork from https://github.com/sindresorhus/macos-version +// cause I can't change it to common-js module +import process from 'process' +import fs from 'fs' +import semver from 'semver' + +export const isMacOS = process.platform === 'darwin' + +let version: string | undefined + +const clean = (version: string) => { + const { length } = version.split('.') + + if (length === 1) { + return `${version}.0.0` + } + + if (length === 2) { + return `${version}.0` + } + + return version +} + +const parseVersion = (plist: string) => { + const matches = /ProductVersion<\/key>\s*([\d.]+)<\/string>/.exec(plist) + if (!matches) { + return + } + + return matches[1].replace('10.16', '11') +} + +export function macOSVersion (): string { + if (!isMacOS) { + return '' + } + + if (!version) { + const file = fs.readFileSync('/System/Library/CoreServices/SystemVersion.plist', 'utf8') + const matches = parseVersion(file) + + if (!matches) { + return '' + } + + version = clean(matches) + } + + return version +} + +if (process.env.NODE_ENV === 'test') { + macOSVersion._parseVersion = parseVersion +} + +export function isMacOSVersion (semverRange: string) { + if (!isMacOS) { + return false + } + + semverRange = semverRange.replace('10.16', '11') + + return semver.satisfies(macOSVersion(), clean(semverRange)) +} + +export function isMacOSVersionGreaterThanOrEqualTo (version: string) { + if (!isMacOS) { + return false + } + + version = version.replace('10.16', '11') + + return semver.gte(macOSVersion(), clean(version)) +} + +export function assertMacOSVersion (semverRange: string) { + semverRange = semverRange.replace('10.16', '11') + + if (!isMacOSVersion(semverRange)) { + throw new Error(`Requires macOS ${semverRange}`) + } +} + +export function assertMacOSVersionGreaterThanOrEqualTo (version: string) { + version = version.replace('10.16', '11') + + if (!isMacOSVersionGreaterThanOrEqualTo(version)) { + throw new Error(`Requires macOS ${version} or later`) + } +} + +export function assertMacOS () { + if (!isMacOS) { + throw new Error('Requires macOS') + } +}