File tree Expand file tree Collapse file tree 3 files changed +25
-8
lines changed
Expand file tree Collapse file tree 3 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,22 @@ func openFile(filename string) error {
196196 if contentType == "" {
197197 return errors .New ("failed to get file content type" )
198198 }
199+ logger .Debugf ("content type: %q" , contentType )
200+
201+ // 处理空文件的情况,根据文件扩展名猜测 content type
202+ if contentType == "application/x-zerosize" {
203+ uncerten , guessedType := gio .ContentTypeGuess (filename , nil )
204+ // 不确定,使用默认本文打开
205+ if uncerten || guessedType == "" {
206+ contentType = "text/plain"
207+ } else if guessedType == "application/x-zerosize" {
208+ contentType = "text/plain"
209+ } else {
210+ logger .Debugf ("empty file detected, guessed content type: %q" , guessedType )
211+ contentType = guessedType
212+
213+ }
214+ }
199215
200216 appInfo := gio .AppInfoGetDefaultForType (contentType , false )
201217 if appInfo == nil {
Original file line number Diff line number Diff line change @@ -7,9 +7,9 @@ require (
77 github.com/fogleman/gg v1.3.0
88 github.com/godbus/dbus/v5 v5.1.0
99 github.com/gosexy/gettext v0.0.0-20160830220431-74466a0a0c4a
10- github.com/linuxdeepin/go-dbus-factory v0.0.0-20250808013927-6368d3237cee
11- github.com/linuxdeepin/go-gir v0.0.0-20250812023606-b28aaee32ac9
12- github.com/linuxdeepin/go-lib v0.0.0-20250812091504-ef74b917a73a
10+ github.com/linuxdeepin/go-dbus-factory v0.0.0-20251106065250-e58866b2c218
11+ github.com/linuxdeepin/go-gir v0.0.0-20251127080441-d9c47dbb6da4
12+ github.com/linuxdeepin/go-lib v0.0.0-20251106065207-1fdf101312e6
1313 github.com/linuxdeepin/go-x11-client v0.0.0-20230131052004-7503e2337ee1
1414 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
1515 github.com/stretchr/testify v1.8.1
Original file line number Diff line number Diff line change @@ -27,12 +27,13 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
2727github.com/kr/pty v1.1.1 /go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ =
2828github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE =
2929github.com/kr/text v0.1.0 /go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI =
30- github.com/linuxdeepin/go-dbus-factory v0.0.0-20250808013927-6368d3237cee h1:466thkbIB3la2qlZI/g4Jv4LypN52iFFLGcG+0F2aqM =
31- github.com/linuxdeepin/go-dbus-factory v0.0.0-20250808013927-6368d3237cee /go.mod h1:iIlTR50SA8MJ9ORPyMOpKWMF4g+AUorbER5AX0RD9Jk =
32- github.com/linuxdeepin/go-gir v0.0.0-20250812023606-b28aaee32ac9 h1:H95pXIA104lsylGPXXPm8rM+6vVsmKff7sJGGgWMu5A =
30+ github.com/linuxdeepin/go-dbus-factory v0.0.0-20251106065250-e58866b2c218 h1:bifQcTysGUacNXM5PK9IWDPCG8Jb/+JzKwy3w8APYq0 =
31+ github.com/linuxdeepin/go-dbus-factory v0.0.0-20251106065250-e58866b2c218 /go.mod h1:dfpixHkqiijg3P7w5QArkMyC7+vlHcutN5R6zHIn8is =
3332github.com/linuxdeepin/go-gir v0.0.0-20250812023606-b28aaee32ac9 /go.mod h1:a0tox5vepTQu5iO6rdKc4diGT+fkyXZlRROM8ULEvaI =
34- github.com/linuxdeepin/go-lib v0.0.0-20250812091504-ef74b917a73a h1:G4wz/sQIg/rd6aJ82Sg4IfKMn/2HV5V2Ia0KS7o6Xhs =
35- github.com/linuxdeepin/go-lib v0.0.0-20250812091504-ef74b917a73a /go.mod h1:2d0hhhqpr9UP9DRgnzU4y6nwdgUtM0qV94Wf0bzAI2g =
33+ github.com/linuxdeepin/go-gir v0.0.0-20251127080441-d9c47dbb6da4 h1:CsW+3eOerOSANbQWEXOWNqJuzl7/W9QIJu9wHvB0g/I =
34+ github.com/linuxdeepin/go-gir v0.0.0-20251127080441-d9c47dbb6da4 /go.mod h1:a0tox5vepTQu5iO6rdKc4diGT+fkyXZlRROM8ULEvaI =
35+ github.com/linuxdeepin/go-lib v0.0.0-20251106065207-1fdf101312e6 h1:ntYWER7pULMpTQykPiENOGh7pxSPCspV3Ql8mZA+IBc =
36+ github.com/linuxdeepin/go-lib v0.0.0-20251106065207-1fdf101312e6 /go.mod h1:2d0hhhqpr9UP9DRgnzU4y6nwdgUtM0qV94Wf0bzAI2g =
3637github.com/linuxdeepin/go-x11-client v0.0.0-20220830090948-78fe92b727bb /go.mod h1:KwpmRZ47A/0a2l9V0V6aTlkuNaqy5j1fOqMFJONuIMY =
3738github.com/linuxdeepin/go-x11-client v0.0.0-20230131052004-7503e2337ee1 h1:UZo2ftrgFtf5O4jtG0dJ+i/AeFy8LXjNewBRDhwzFxA =
3839github.com/linuxdeepin/go-x11-client v0.0.0-20230131052004-7503e2337ee1 /go.mod h1:KwpmRZ47A/0a2l9V0V6aTlkuNaqy5j1fOqMFJONuIMY =
You can’t perform that action at this time.
0 commit comments