github.com/Seikaijyu/gio@v0.0.1/app/app.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  package app
     4  
     5  import (
     6  	"os"
     7  	"path/filepath"
     8  	"strings"
     9  )
    10  
    11  // extraArgs contains extra arguments to append to
    12  // os.Args. The arguments are separated with |.
    13  // Useful for running programs on mobiles where the
    14  // command line is not available.
    15  // Set with the go linker flag -X.
    16  var extraArgs string
    17  
    18  // ID is the app id exposed to the platform.
    19  //
    20  // On Android ID is the package property of AndroidManifest.xml,
    21  // on iOS ID is the CFBundleIdentifier of the app Info.plist,
    22  // on Wayland it is the toplevel app_id,
    23  // on X11 it is the X11 XClassHint
    24  //
    25  // ID is set by the gogio tool or manually with the -X linker flag. For example,
    26  //
    27  //	go build -ldflags="-X 'github.com/Seikaijyu/gio/app.ID=org.gioui.example.Kitchen'" .
    28  //
    29  // Note that ID is treated as a constant, and that changing it at runtime
    30  // is not supported. Default value of ID is filepath.Base(os.Args[0]).
    31  var ID = ""
    32  
    33  func init() {
    34  	if extraArgs != "" {
    35  		args := strings.Split(extraArgs, "|")
    36  		os.Args = append(os.Args, args...)
    37  	}
    38  	if ID == "" {
    39  		ID = filepath.Base(os.Args[0])
    40  	}
    41  }
    42  
    43  // DataDir returns a path to use for application-specific
    44  // configuration data.
    45  // On desktop systems, DataDir use os.UserConfigDir.
    46  // On iOS NSDocumentDirectory is queried.
    47  // For Android Context.getFilesDir is used.
    48  //
    49  // BUG: DataDir blocks on Android until init functions
    50  // have completed.
    51  func DataDir() (string, error) {
    52  	return dataDir()
    53  }
    54  
    55  // Main must be called last from the program main function.
    56  // On most platforms Main blocks forever, for Android and
    57  // iOS it returns immediately to give control of the main
    58  // thread back to the system.
    59  //
    60  // Calling Main is necessary because some operating systems
    61  // require control of the main thread of the program for
    62  // running windows.
    63  func Main() {
    64  	osMain()
    65  }