简体   繁体   中英

Go - how to detect if the Windows or Mac desktop screen is landscape or portrait mode?

With Go, how can i detect if the Windows or Mac PC is in landscape or portrait mode please? here is a following example where i need to read the action for layout if its landscape or portrait.

package main

import "os/exec"
import "runtime"
import "fmt"

const url = "http://localhost:8080/demo1?action=landscape"


func main() {      
  myos := runtime.GOOS
  /////------------------> Detect the landscape or portrait of the screen???


  if myos == "windows" {
    chrome := "C:/Program Files/Google/Chrome/Application/chrome.exe"
    cmd := exec.Command(chrome, "--chrome-frame", "--kiosk", url)
    err := cmd.Start()
    if err != nil {
      // 64-bit
      //println("Failed to start chrome:", err)
      chrome := "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
      cmd := exec.Command(chrome, "--chrome-frame", "--kiosk", url)
      cmd.Start()       
    } 

  } else if myos == "darwin" {
    // open -b com.google.Chrome --args <which args to pass to Chrome>
    // "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
    //chrome := "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
    cmd := exec.Command("open", "-b" , "com.google.Chrome", "--args", "--chrome-frame", "--kiosk", url)
    err := cmd.Start()
    if err != nil {
      fmt.Println("failed")
    } 

  } else {
    //Linux    
    chrome := "google-chrome"
    cmd := exec.Command(chrome, "--chrome-frame", "--kiosk", url)
    err := cmd.Start()
    if err != nil {
      fmt.Println("failed")
    }

  }

}

Once again, not a direct answer to your question, but may solve your problem.

See this for a description. All you really need to do is check the dimensions of the window via javascript and reload the page with the correct args.

if height > width, it's portrait mode, otherwise it's landscape

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM