mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-02-02 02:58:13 -05:00
parent
dee40a6bcd
commit
4ebdc721e4
Binary file not shown.
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 1.1 KiB |
BIN
public/menubar-newdarwin@2.png
Normal file
BIN
public/menubar-newdarwin@2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
public/menubar-newdarwin@3.png
Normal file
BIN
public/menubar-newdarwin@3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
@ -18,6 +18,7 @@ import pkg from 'root/package.json'
|
|||||||
import { handleCopyUrl } from '~/main/utils/common'
|
import { handleCopyUrl } from '~/main/utils/common'
|
||||||
import { privacyManager } from '~/main/utils/privacyManager'
|
import { privacyManager } from '~/main/utils/privacyManager'
|
||||||
import { T } from '#/i18n'
|
import { T } from '#/i18n'
|
||||||
|
import { isMacOSVersionGreaterThanOrEqualTo } from '~/main/utils/getMacOSVersion'
|
||||||
let contextMenu: Menu | null
|
let contextMenu: Menu | null
|
||||||
let menu: Menu | null
|
let menu: Menu | null
|
||||||
let tray: Tray | 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 () {
|
export function createTray () {
|
||||||
const menubarPic = process.platform === 'darwin' ? `${__static}/menubar.png` : `${__static}/menubar-nodarwin.png`
|
const menubarPic = getTrayIcon()
|
||||||
tray = new Tray(menubarPic)
|
tray = new Tray(menubarPic)
|
||||||
// click事件在Mac和Windows上可以触发(在Ubuntu上无法触发,Unity不支持)
|
// click事件在Mac和Windows上可以触发(在Ubuntu上无法触发,Unity不支持)
|
||||||
if (process.platform === 'darwin' || process.platform === 'win32') {
|
if (process.platform === 'darwin' || process.platform === 'win32') {
|
||||||
|
97
src/main/utils/getMacOSVersion.ts
Normal file
97
src/main/utils/getMacOSVersion.ts
Normal file
@ -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 = /<key>ProductVersion<\/key>\s*<string>([\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')
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user