Skip to content

Commit 0237346

Browse files
committed
fix: can't copy image record
1 parent 2545e6c commit 0237346

10 files changed

Lines changed: 77 additions & 49 deletions

File tree

config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func LoadConfig() (*Config, error) {
7070
}
7171
}
7272

73-
viper.SetDefault("info.version", "0.3.0")
73+
viper.SetDefault("info.version", "0.3.1")
7474
viper.SetDefault("info.productName", "Devboard")
7575
viper.SetDefault("UserConfigDir", data_dir)
7676
viper.SetDefault("UserConfigName", "settings.json")

frontend/src/biz/shortcut/shortcut.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function ShortcutModel(props: {}) {
1111
refresh() {
1212
bus.emit(Events.StateChange, { ..._state });
1313
},
14-
register(handlers: Record<string, (event: KeyboardEvent) => void>) {
14+
register(handlers: Record<string, (event: KeyboardEvent & { step?: 'keydown' | 'keyup' }) => void>) {
1515
const keys = Object.keys(handlers);
1616
for (let i = 0; i < keys.length; i += 1) {
1717
const handle_key = keys[i];
@@ -65,10 +65,22 @@ export function ShortcutModel(props: {}) {
6565
const handler = _shortcut_map[key1];
6666
if (handler) {
6767
// console.log("[BIZ]shortcut - key1 bingo!", key1, step);
68+
// @ts-ignore
69+
event.step = step;
6870
handler(event);
6971
return;
7072
}
7173
}
74+
// 会触发两次啊,不行
75+
// if (step === "keyup" && key1.includes("+")) {
76+
// const handler = _shortcut_map[key1];
77+
// if (handler) {
78+
// // @ts-ignore
79+
// event.step = step;
80+
// handler(event);
81+
// return;
82+
// }
83+
// }
7284
if (step === "keydown" && key2) {
7385
// methods.invokeHandlers(event, key2);
7486
const handler = _shortcut_map[key2];
@@ -100,7 +112,7 @@ export function ShortcutModel(props: {}) {
100112
const ui = {};
101113

102114
let _handlers: Handler<TheTypesOfEvents[Events.Shortcut]>[] = [];
103-
let _shortcut_map: Record<string, (event: { code: string; preventDefault: () => void }) => void> = {};
115+
let _shortcut_map: Record<string, (event: { code: string; step?: 'keydown' | 'keyup'; preventDefault: () => void }) => void> = {};
104116
let _pressed_codes: string[] = [];
105117
let _pressed_code_map: Record<string, boolean> = {};
106118
let _continuous_timer: NodeJS.Timeout | number | null = null;
@@ -127,7 +139,7 @@ export function ShortcutModel(props: {}) {
127139
methods,
128140
ui,
129141
state: _state,
130-
ready() {},
142+
ready() { },
131143
destroy() {
132144
bus.destroy();
133145
},

frontend/src/components/dynamic-content/with-click.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export function ModelInList<T>(props: {}) {
1111
bus.emit(Events.StateChange, { ..._state });
1212
},
1313
set(uid: string, v: () => T) {
14-
console.log("set", uid);
14+
// console.log("set", uid);
1515
const existing = _cache.get(uid);
1616
if (existing) {
1717
return;
1818
}
1919
_cache.set(uid, v());
2020
},
2121
get(uid: string) {
22-
console.log("get", uid);
22+
// console.log("get", uid);
2323
return _cache.get(uid) ?? null;
2424
},
2525
};

frontend/src/domains/list-select/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function ListSelectModel(props: { $view: ScrollViewCore; num?: number })
6464
},
6565
moveToNextOption(opt: Partial<{ step: number; force: boolean }> = {}) {
6666
const { step = 1, force = false } = opt;
67-
console.log("[COMPONENT]with-tags-input - moveToNextOption", _opt_idx, _options);
67+
// console.log("[DOMAIN]list-select - moveToNextOption", _opt_idx, _options);
6868
if (_options.length === 0) {
6969
return;
7070
}

frontend/src/pages/helper_center/shortcut.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function HelperCenterShortcutView(props: ViewComponentProps) {
7373
<tbody>
7474
<tr>
7575
<td class="p-2 w-[280px]">
76-
<ShortcutKey keys={["Ctrl", "Shift", "M"]} separator="+" />
76+
<ShortcutKey keys={["Ctrl", "~"]} separator="+" />
7777
</td>
7878
<td class="p-2">
7979
<div>macOS端</div>

frontend/src/pages/home/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ function HomeIndexViewModel(props: ViewComponentProps) {
426426
ui.$list_select.methods.moveToPrevOption({ step: 3, force: true });
427427
},
428428
"KeyJ,ArrowDown"(event) {
429-
console.log("[]shortcut - KeyJ", ui.$input_search.isFocus, ui.$input_search.isOpen, event.code);
429+
// console.log("[]shortcut - KeyJ", ui.$input_search.isFocus, ui.$input_search.isOpen, event.code);
430430
// console.log("[]shortcut - moveToNextOption");
431431
if (ui.$input_search.isFocus) {
432432
if (event.code === "ArrowDown") {
@@ -513,6 +513,12 @@ function HomeIndexViewModel(props: ViewComponentProps) {
513513
Escape() {
514514
ui.$input_search.methods.blur();
515515
},
516+
EscapeEscape(event) {
517+
setTimeout(() => {
518+
Events.Emit({ name: "m:hide-main-window", data: null });
519+
// 100 是为了 keyup 能正确清除掉按下的 Esc
520+
}, 100);
521+
},
516522
});
517523

518524
request.paste.list.onStateChange(() => methods.refresh());

internal/biz/shortcut_darwin.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
package biz
44

55
import (
6-
"fmt"
7-
86
"golang.design/x/hotkey"
97
)
108

119
// const ModCommandKey = hotkey.ModCmd
1210
func NewHotkey() *hotkey.Hotkey {
13-
fmt.Println("[]register hotkey in darwin")
14-
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCmd, hotkey.ModShift}, hotkey.KeyM)
11+
// fmt.Println("[]register hotkey in darwin")
12+
// hk := hotkey.New([]hotkey.Modifier{hotkey.ModCmd, hotkey.ModShift}, hotkey.KeyM)
13+
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCmd}, hotkey.Key(0x32))
1514
return hk
1615
}

internal/biz/shortcut_windows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ import (
1010
func NewHotkey() *hotkey.Hotkey {
1111
// fmt.Println("[]register hotkey")
1212
// hk := hotkey.New([]hotkey.Modifier{}, hotkey.)
13-
return &hotkey.Hotkey{}
13+
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl}, hotkey.Key(0xC0))
14+
return hk
1415
}

internal/service/paste.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ func (s *PasteService) Write(body PasteboardWriteBody) *Result {
187187
if record.FileListJSON != "" {
188188
is_file = true
189189
}
190-
191190
if is_html {
192191
s.Biz.ManuallyWriteClipboardTime = time.Now()
193192
text := record.Html
@@ -199,13 +198,6 @@ func (s *PasteService) Write(body PasteboardWriteBody) *Result {
199198
}
200199
return Ok(nil)
201200
}
202-
if is_text {
203-
s.Biz.ManuallyWriteClipboardTime = time.Now()
204-
if err := clipboard.WriteText(record.Text); err != nil {
205-
return Error(err)
206-
}
207-
return Ok(nil)
208-
}
209201
if is_image {
210202
s.Biz.ManuallyWriteClipboardTime = time.Now()
211203
decoded_data, err := base64.StdEncoding.DecodeString(record.ImageBase64)
@@ -241,6 +233,13 @@ func (s *PasteService) Write(body PasteboardWriteBody) *Result {
241233
}
242234
return Ok(nil)
243235
}
236+
if is_text {
237+
s.Biz.ManuallyWriteClipboardTime = time.Now()
238+
if err := clipboard.WriteText(record.Text); err != nil {
239+
return Error(err)
240+
}
241+
return Ok(nil)
242+
}
244243
return Error(fmt.Errorf("invalid record data"))
245244
}
246245

main.go

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"embed"
66
"fmt"
77
"io/fs"
8-
"log"
98
"net/http"
109
"net/url"
1110
"runtime"
@@ -227,9 +226,12 @@ func main() {
227226
}
228227
menu := app.NewMenu()
229228
m_main := menu.Add("Show Devboard")
230-
if runtime.GOOS == "darwin" {
231-
m_main.SetAccelerator("CmdOrCtrl+Shift+M")
232-
}
229+
// if runtime.GOOS == "darwin" {
230+
// m_main.SetAccelerator("CmdOrCtrl+Shift+M")
231+
// }
232+
// if runtime.GOOS == "windows" {
233+
// m_main.SetAccelerator("CmdOrCtrl+Backquote")
234+
// }
233235
m_main.OnClick(func(ctx *application.Context) {
234236
win.Show()
235237
win.Focus()
@@ -339,6 +341,9 @@ func main() {
339341
search := fmt.Sprintf("?title=%v&desc=%v", body.Title, body.Content)
340342
biz.ShowErrorWindow(search)
341343
})
344+
app.Event.On("m:hide-main-window", func(event *application.CustomEvent) {
345+
win.Hide()
346+
})
342347
go func() {
343348
machine_id, err := machineid.ID()
344349
if err != nil {
@@ -381,6 +386,35 @@ func main() {
381386
biz.SetUserConfig(biz_config)
382387
// win.Show()
383388
}()
389+
390+
var register_global_shortcut func(win *application.WebviewWindow, hk *hotkey.Hotkey)
391+
register_global_shortcut = func(win *application.WebviewWindow, hk *hotkey.Hotkey) {
392+
// hk := hotkey.New([]hotkey.Modifier{hotkey.ModCmd, hotkey.ModShift}, hotkey.KeyM)
393+
if err := hk.Register(); err != nil {
394+
t := fmt.Sprintf("hotkey: failed to register hotkey: %v", err)
395+
biz.ShowErrorWindow("?" + url.QueryEscape("title=InitializeFailed&desc="+t))
396+
return
397+
}
398+
// log.Printf("hotkey: %v is registered\n", hk)
399+
<-hk.Keydown()
400+
// log.Printf("hotkey: %v is down\n", hk)
401+
<-hk.Keyup()
402+
// log.Printf("hotkey: %v is up\n", hk)
403+
if err := hk.Unregister(); err != nil {
404+
t := fmt.Sprintf("hotkey: failed to unregister hotkey: %v", err)
405+
biz.ShowErrorWindow("?" + url.QueryEscape("title=Shortcut&desc="+t))
406+
return
407+
}
408+
// log.Printf("hotkey: %v is unregistered\n", hk)
409+
if win.IsVisible() {
410+
win.Hide()
411+
} else {
412+
win.Show()
413+
win.Focus()
414+
}
415+
register_global_shortcut(win, hk)
416+
}
417+
384418
go func() {
385419
register_global_shortcut(win, hk)
386420
}()
@@ -392,26 +426,3 @@ func main() {
392426
fmt.Println(err.Error())
393427
}
394428
}
395-
396-
func register_global_shortcut(win *application.WebviewWindow, hk *hotkey.Hotkey) {
397-
// hk := hotkey.New([]hotkey.Modifier{hotkey.ModCmd, hotkey.ModShift}, hotkey.KeyM)
398-
err := hk.Register()
399-
if err != nil {
400-
log.Fatalf("hotkey: failed to register hotkey: %v", err)
401-
return
402-
}
403-
// log.Printf("hotkey: %v is registered\n", hk)
404-
<-hk.Keydown()
405-
// log.Printf("hotkey: %v is down\n", hk)
406-
<-hk.Keyup()
407-
// log.Printf("hotkey: %v is up\n", hk)
408-
hk.Unregister()
409-
// log.Printf("hotkey: %v is unregistered\n", hk)
410-
if win.IsVisible() {
411-
win.Hide()
412-
} else {
413-
win.Show()
414-
win.Focus()
415-
}
416-
register_global_shortcut(win, hk)
417-
}

0 commit comments

Comments
 (0)