diff options
author | 无闻 <u@gogs.io> | 2015-08-04 08:51:06 +0800 |
---|---|---|
committer | 无闻 <u@gogs.io> | 2015-08-04 08:51:06 +0800 |
commit | 96c1ce960602d65252fbb038e10db629f235936d (patch) | |
tree | 8970c3fe3c95ec93562b1b3ff6e51b6b27fe2fe6 /modules/middleware/repo.go | |
parent | 8e8d535e233966acd1510df78c01e11dc8156514 (diff) | |
parent | eebcbf9d3438a9910dee56fd76ab624726eb207c (diff) | |
download | gitea-96c1ce960602d65252fbb038e10db629f235936d.tar.gz gitea-96c1ce960602d65252fbb038e10db629f235936d.zip |
Merge pull request #1432 from manfer/enhance-copy-clipboard
Enhance copy clipboard
Diffstat (limited to 'modules/middleware/repo.go')
-rw-r--r-- | modules/middleware/repo.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index a200d6d66f..e8a362bd4d 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -16,6 +16,14 @@ import ( "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/setting" + + "github.com/hashicorp/go-version" + "github.com/mssola/user_agent" +) + +const ( + FIREFOX_COPY_SUPPORT = "41.0" + CHROME_COPY_SUPPORT = "43.0.2356" ) func ApiRepoAssignment() macaron.Handler { @@ -345,6 +353,24 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { ctx.Data["BranchName"] = ctx.Repo.BranchName ctx.Data["CommitId"] = ctx.Repo.CommitId + + userAgent := ctx.Req.Header.Get("User-Agent") + ua := user_agent.New(userAgent); + browserName, browserVer := ua.Browser() + + sliceVer := strings.Split(browserVer, ".") + var max int + if max = len(sliceVer); 3 < max { + max = 3 + } + browserVer = strings.Join(sliceVer[:max], ".") + + browserVersion, err := version.NewVersion(browserVer) + chromeConstraint, err := version.NewConstraint(">= " + CHROME_COPY_SUPPORT) + firefoxConstraint, err := version.NewConstraint(">= " + FIREFOX_COPY_SUPPORT) + + ctx.Data["BrowserSupportsCopy"] = (browserName == "Chrome" && chromeConstraint.Check(browserVersion)) || (browserName == "Firefox" && firefoxConstraint.Check(browserVersion)) + } } |