# app（應用）

下面範例為 `app` 的常用屬性：

```javascript
console.log(eagle.app.version);				// Eagle 版本
console.log(eagle.app.build);				// Eagle Build 號
console.log(eagle.app.locale);				// 應用介面語系，en/zh_CN/zh_TW/ja_JP
console.log(eagle.app.arch);				// x86 | x64
console.log(eagle.app.platform);			// darwin | win32
console.log(eagle.app.isWindows);			// true | false, 作業系統是否為 Windows
console.log(eagle.app.isMac);				// true | false, 作業系統是否為 Mac
console.log(eagle.app.runningUnderARM64Translation);	// 是否執行於 rosetta 轉譯模式
```

## 方法 <a href="#z1a5y" id="z1a5y"></a>

## isDarkColors() <a href="#a6hjz" id="a6hjz"></a>

確認當前系統是否處於深色（Dark）模式。

* 返回 `boolean` - 當前系統是否正在處於 Dark 模式。

```javascript
eagle.app.isDarkColors();		// true | false
```

## getPath(name) <a href="#b8lgu" id="b8lgu"></a>

您可以透過名稱請求以下路徑

* `name` string - 您可以透過名稱請求以下路徑
  * `home` - 使用者的 home 資料夾（主目錄）
  * `appData` - 每個使用者的應用程式數據目錄，預設情況下指向：
  * `userData` - 儲存你應用程式設定檔案的資料夾，預設是 appData 資料夾附加應用的名稱 按照習慣使用者儲存的數據檔案應該寫在此目錄，同時不建議在這寫大檔案，因為某些環境會備份此目錄到雲端儲存。
  * `temp` - 臨時資料夾
  * `exe` - 當前的可執行檔案
  * `desktop` - 當前使用者的桌面資料夾
  * `documents` - 使用者文件目錄的路徑
  * `downloads` - 使用者下載目錄的路徑
  * `music` - 使用者音樂目錄的路徑
  * `pictures` - 使用者圖片目錄的路徑
  * `videos` - 使用者影片目錄的路徑
  * `recent` - 使用者最近檔案的目錄 (僅限 Windows)。
* 返回 `Promise<path: string>` - `path` 查詢路徑結果。

```javascript
await eagle.app.getPath('appData');	// 'C:\Users\User\AppData\Roaming'
await eagle.app.getPath('pictures');	// 'C:\Users\User\Pictures'
await eagle.app.getPath('desktop');	// 'C:\Users\User\Desktop'
```

{% hint style="info" %}
備註：此功能與 Electron API 的 [app.getPath](https://www.electronjs.org/zh/docs/latest/api/app#appgetapppath) 功能類似。
{% endhint %}

## getFileIcon(path\[, options]) <a href="#ndrop" id="ndrop"></a>

取得指定路徑檔案關聯的圖示。

* `path` string - 欲取得圖示之檔案路徑
* `options` Object（可選）
  * `size` string
  * `small` - 16x16
  * `normal` - 32x32
  * `large` - `Windows` 為 32x32, `macOS` 不支援。
* 返回 `Promise<img: NativeImage>`
  * `img` [NativeImage](https://www.electronjs.org/zh/docs/latest/api/native-image) - 一個 NativeImage 類型的應用圖示。

```javascript
let img = await eagle.app.getFileIcon('path_to_file', { size: 'small' });

// 取得圖片資訊
let base64 = img.toDataURL();
let size = img.getSize();	// {'width': 16, height: 16}

// 儲存到電腦
let buffer = img.toPNG();
require('fs').writeFileSync('output_path/example.png', buffer);
```

{% hint style="info" %}
備註：此功能與 Electron API 的 [app.getAppIcon](https://www.electronjs.org/zh/docs/latest/api/app#appgetfileiconpath-options) 功能類似。
{% endhint %}

## createThumbnailFromPath(path, maxSize) <a href="#psczp" id="psczp"></a>

取得指定路徑檔案關聯的圖示。

* `path` string - 欲取得縮圖之檔案路徑
* `maxSize` Size - 返回縮圖的最大寬度和高度(正數)。 在 Windows 平台下將忽略 maxSize.height 並根據 maxSize.width 縮放高度
* 返回 `Promise<img: NativeImage>`
  * `img` [NativeImage](https://www.electronjs.org/zh/docs/latest/api/native-image) - 檔案的縮圖預覽圖片。

```javascript
let img = await eagle.app.createThumbnailFromPath('path_to_file', { 
    height: 200, 
    width: 200 
});

// 取得圖片資訊
let base64 = img.toDataURL();
let size = img.getSize();	// {'width': 200, height: 150}

// 儲存到電腦
let buffer = img.toPNG();
require('fs').writeFileSync('output_path/example.png', buffer);
```

{% hint style="info" %}
備註：此功能與 Electron API 的 [nativeImage.createThumbnailFromPath(path, maxSize)](https://www.electronjs.org/zh/docs/latest/api/native-image#nativeimagecreatethumbnailfrompathpath-maxsize-macos-windows) 功能類似。
{% endhint %}

## show() <a href="#show" id="show"></a>

將 Eagle 主應用程序視窗喚起並顯示在畫面最上方。

* 返回 `Promise<boolean>` - 操作是否成功。

```javascript
await eagle.app.show();
```

{% hint style="info" %}
備註：此功能需要 Eagle 4.0 build18 或更高版本。
{% endhint %}

## 屬性 <a href="#adtwq" id="adtwq"></a>

## version <a href="#f95hw" id="f95hw"></a>

`string` 屬性，取得目前 Eagle 應用程式版本。

## build <a href="#gwrv2" id="gwrv2"></a>

`number` 屬性，取得目前 Eagle 應用程式 Build Number。

## locale <a href="#dd0fm" id="dd0fm"></a>

`string` 屬性，取得目前 Eagle 應用程式介面語系。

* `en` - 英文
* `zh_CN` - 簡體中文
* `zh_TW` - 繁體中文
* `ja_JP` - 日文
* `ko_KR` - 韓文
* `es_ES` - 西班牙文
* `de_DE` - 德文
* `ru_RU` - 俄文

## arch <a href="#hqmzh" id="hqmzh"></a>

`string` 屬性，返回作業系統 CPU 架構。

* `x64`
* `arm64`
* `x86`

## platform <a href="#z5qbr" id="z5qbr"></a>

`string` 屬性，返回一個標識作業系統平台的字串。

* `darwin` - macOS 作業系統
* `win32` - Windows 作業系統

## env <a href="#bdd4y" id="bdd4y"></a>

`Object` 屬性，返回環境變數的物件。

```javascript
console.log(eagle.app.env);

{
  APPDATA: "C:\\Users\\User\\AppData\\Roaming",
  HOMEDRIVE: "C:",
	HOMEPATH: "\\Users\\User",
  LANG: "zh_TW.UTF-8",
  TEMP: "C:\\Users\\User\\AppData\\Local\\Temp"
}
```

```javascript
console.log(eagle.app.env['TEMP']);

"C:\\Users\\User\\AppData\\Local\\Temp"
```

## execPath <a href="#uvg0k" id="uvg0k"></a>

`string` 屬性，當前應用程式執行路徑。

```javascript
console.log(eagle.app.execPath);

"C:\\Program Files\\Eagle\\Eagle.exe"
```

## pid <a href="#cldbp" id="cldbp"></a>

`number` 屬性，當前插件程式 id。

## isWindows <a href="#u8kad" id="u8kad"></a>

`boolean` 屬性，是否當前為 Window 作業系統。

## isMac <a href="#qw2s4" id="qw2s4"></a>

`boolean` 屬性，是否當前為 Mac 作業系統。

## runningUnderARM64Translation <a href="#kbkmv" id="kbkmv"></a>

`boolean` 屬性，為 true 時表明目前應用正在使用 ARM64 執行環境 (例如 macOS [Rosetta Translator Environment](https://en.wikipedia.org/wiki/Rosetta_\(software\)) 或者 Windows [WOW](https://en.wikipedia.org/wiki/Windows_on_Windows)).

{% hint style="info" %}
提示：此功能與 Electron API 的 [app.runningUnderARM64Translation](https://www.electronjs.org/zh/docs/latest/api/app#apprunningunderarm64translation-%E5%8F%AA%E8%AF%BB-macos-windows) 功能類似，您可以使用此屬性來提示使用者下載應用程式的 arm64 版本，當使用者錯誤地在轉譯環境下執行 x64 版本。
{% endhint %}

## theme <a href="#cztqx" id="cztqx"></a>

`string` 屬性， - 當前主題配色的名稱，如 `LIGHT`、`LIGHTGRAY`、`GRAY`、`DARK`、`BLUE`、`PURPLE`。

## userDataPath <a href="#ud9km" id="ud9km"></a>

`string` 屬性，當前使用者資料目錄的路徑。

```javascript
console.log(eagle.app.userDataPath);

"C:\\Users\\User\\AppData\\Roaming\\Eagle"
```

{% hint style="info" %}
備註：此功能需要 Eagle 4.0 build12 或更高版本。
{% endhint %}

### &#x20;<a href="#nptwx" id="nptwx"></a>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.eagle.cool/plugin-api/zh-tw/api/app.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
