-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(open_explorer): don't execute command on Termux (#718)
* fix(open_explorer): don't execute command on Termux * fix: build arm64 in the `test` CI
- Loading branch information
1 parent
412777b
commit 35d6ac7
Showing
4 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package util | ||
|
||
import "os" | ||
|
||
// isTermux 是否在 Termux 中运行 | ||
// | ||
// https://wiki.termux.com/wiki/Getting_started | ||
func isTermux() bool { | ||
return os.Getenv("PREFIX") == "/data/data/com.termux/files/usr" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package util | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
// TestIsTermux 测试在或不在 Termux 中运行都能正确判断 | ||
func TestIsTermux(t *testing.T) { | ||
// 模拟在 Termux 中运行 | ||
os.Setenv("PREFIX", "/data/data/com.termux/files/usr") | ||
|
||
if !isTermux() { | ||
t.Error("期待 isTermux 返回 true,但得到 false。") | ||
} | ||
|
||
// 清除 PREFIX 变量,模拟不在 Termux 中运行 | ||
os.Unsetenv("PREFIX") | ||
|
||
if isTermux() { | ||
t.Error("期待 isTermux 返回 false,但得到 true。") | ||
} | ||
} |