Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
showlotus committed Sep 6, 2024
1 parent e6153ea commit 0d4909f
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 103 deletions.
4 changes: 2 additions & 2 deletions LOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ npm install --global --production windows-build-tools@4.0.0

## log

### 09/04
### 09/06

- 关于 `settings` 的更新,考虑到在任务栏里也能更新一些配置,以及系统主题更新后,需要通知剪贴板更新。
- 关于 `settings` 的更新,考虑到在任务栏里也能更新一些配置,以及系统主题更新后,需要通知剪贴板更新。

### 08/28

Expand Down
1 change: 1 addition & 0 deletions electron/i18n/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
105 changes: 9 additions & 96 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { fileURLToPath } from 'node:url'

import './ipc'
import { SettingsStore } from './store'
import { initTray } from './tray'

const require = createRequire(import.meta.url)
const __dirname = path.dirname(fileURLToPath(import.meta.url))
Expand Down Expand Up @@ -93,7 +94,6 @@ if (!app.requestSingleInstanceLock()) {
}

let win: BrowserWindow | null = null
let tray: Tray | null = null
const preload = path.join(__dirname, '../preload/index.mjs')
const indexHtml = path.join(RENDERER_DIST, 'index.html')

Expand Down Expand Up @@ -123,13 +123,13 @@ if (app.isPackaged) {
// SettingsStore.set('theme', 'system')
// }

SettingsStore.onDidChange('shortcutKey', (newVal, oldVal) => {
console.log('shortcutKey changed', newVal, oldVal)
})
SettingsStore.onDidChange('theme', (newVal, oldVal) => {
// nativeTheme.themeSource = newVal
console.log('theme changed', newVal, oldVal)
})
// SettingsStore.onDidChange('shortcutKey', (newVal, oldVal) => {
// console.log('shortcutKey changed', newVal, oldVal)
// })
// SettingsStore.onDidChange('theme', (newVal, oldVal) => {
// // nativeTheme.themeSource = newVal
// console.log('theme changed', newVal, oldVal)
// })

const RecordStore = new ElectronStore({
cwd: 'Records'
Expand Down Expand Up @@ -344,94 +344,7 @@ async function createWindow() {
win.webContents.send('update-theme', SettingsStore.get('theme'))
})

// TODO 创建系统托盘
tray = new Tray(path.join(process.env.VITE_PUBLIC, 'icon/png/logo.png'))
// 点击系统托盘图标时,打开窗口
tray.on('click', () => {
!win.isVisible() && win.show()
})
const contextMenu = Menu.buildFromTemplate([
{
label: '开机启动',
type: 'checkbox',
checked: true,
click(e) {
// 设置开机自启
app.setLoginItemSettings({
openAtLogin: e.checked,
args: ['--openAsHidden']
})
console.log('Startup', e.checked)
}
},
{ label: '', type: 'separator' },
{
label: 'zh_CN',
type: 'radio',
checked: isZh,
click() {
updateLanguage('zh_CN')
}
},
{
label: 'en_US',
type: 'radio',
checked: !isZh,
click() {
updateLanguage('en_US')
}
},
{ label: '', type: 'separator' },
{
// label: 'System preference',
label: '跟随系统',
type: 'radio',
checked: true,
click() {
nativeTheme.themeSource = 'system'
SettingsStore.set('theme', 'system')
console.log('Theme choose System preference')
}
},
{
// label: 'Light',
label: '浅色',
type: 'radio',
click() {
nativeTheme.themeSource = 'light'
SettingsStore.set('theme', 'light')
console.log('Theme choose Light')
}
},
{
// label: 'Dark',
label: '暗色',
type: 'radio',
click() {
nativeTheme.themeSource = 'dark'
SettingsStore.set('theme', 'dark')
console.log('Theme choose Dark')
}
},
{ label: '', type: 'separator' },
{
label: '检查更新',
type: 'normal',
click() {
// TODO 检查更新
console.log('检查更新')
}
},
{
label: '退出',
type: 'normal',
click() {
app.quit()
}
}
])
tray.setToolTip('NeedClipboard')
tray.setContextMenu(contextMenu)
initTray(win)

registerShortcut()
win.on('show', () => {
Expand Down
65 changes: 65 additions & 0 deletions electron/main/tray.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { BrowserWindow, Menu, Tray, app } from 'electron'
import path from 'node:path'

import pkg from '../../package.json'
import { SettingsStore } from './store'

export let tray: Tray | null

export function initTray(win: BrowserWindow) {
// TODO 托盘图标替换
tray = new Tray(path.join(process.env.VITE_PUBLIC, 'icon/png/logo.png'))
console.log(SettingsStore.get('shortcutKey'))

tray.on('click', () => {
!win.isVisible() && win.show()
})
tray.setToolTip(pkg.name)

const updateMenu = () => {
const startup = SettingsStore.get('startup')
const shortcutKey = SettingsStore.get('shortcutKey').replace(/\s/g, '+')
tray.setContextMenu(genMenu(startup, shortcutKey))
}
updateMenu()
SettingsStore.onDidChange('shortcutKey', updateMenu)
SettingsStore.onDidChange('startup', updateMenu)
}

function genMenu(startup: boolean, shortcutAccelerator: string) {
console.log('shortcutAccelerator', shortcutAccelerator)
return Menu.buildFromTemplate([
{
label: '开机启动',
type: 'checkbox',
checked: startup,
click(e) {
// 设置开机自启
app.setLoginItemSettings({
openAtLogin: e.checked,
args: ['--openAsHidden']
})
SettingsStore.set('startup', e.checked)
}
},
{ label: '', type: 'separator' },
{
label: '打开',
type: 'normal',
accelerator: shortcutAccelerator
},
{
label: '检查更新',
type: 'normal',
click() {
// TODO 检查更新
console.log('检查更新')
}
},
{
label: '退出',
type: 'normal',
role: 'quit'
}
])
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "NeedClipboard",
"version": "1.0.0-beta.1",
"version": "0.1.0-beta.1",
"main": "dist-electron/main/index.js",
"description": "Really simple Electron + Vue + Vite boilerplate.",
"author": "草鞋没号 <308487730@qq.com>",
Expand Down Expand Up @@ -67,4 +67,4 @@
"conf@13.0.1": "patches/conf@13.0.1.patch"
}
}
}
}
4 changes: 2 additions & 2 deletions src/components/CodeBlock.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div
class="py-1 px-1 flex gap-2 items-center text-xs rounded"
class="py-1 px-1 flex gap-2 items-center text-xs rounded text-[--nc-code-color] font-bold"
:class="{
'group hover:bg-[--nc-item-color-hover]': openHoverStyle
}"
Expand All @@ -10,7 +10,7 @@
<span
v-for="(t, i) in keys"
:key="i"
class="py-1 px-1.5 rounded font-bold bg-[--nc-code-bg-color] text-[--nc-code-color] group-hover:bg-[--nc-code-bg-active-color]"
class="py-1 px-1.5 rounded bg-[--nc-code-bg-color] group-hover:bg-[--nc-code-bg-active-color]"
>{{ t }}</span
>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Shortcut.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
contenteditable="false"
:value="recordingKeys"
:open-hover-style="false"
class="-ml-1"
class="-ml-1 !text-[--el-text-color-regular] !font-normal"
/>
<span ref="gapRef" class="w-0.5">{{ ' ' }}</span>
</div>
Expand Down

0 comments on commit 0d4909f

Please sign in to comment.