Quick Start
This document explains how to use GM Web SDK to develop and integrate frontend apps. GM Web SDK provides frontend developers with a rich set of APIs covering file operations, terminal interaction, system integration, and other core features, so your app can integrate deeply with the GM ecosystem.
When to use
GM Web SDK is intended for web apps that need deep integration with the GM platform, including but not limited to:
- Open the file system
- Open a terminal
- Open the code editor
- Upload files
Quick Start
Installation and importing
Option 1: import with a <script> tag
You can load the GM SDK into an HTML page in either of the following ways:
Option A: CDN (recommended for quick testing)
<script src="https://down-gmb.oss-cn-zhangjiakou.aliyuncs.com/appWebJs/gmAppSdk.js"></script>Option B: local file (recommended for production)
Local deployment
To keep production stable and fast to load, download the SDK file into your project and serve it locally.
Download the SDK file into your project directory:
# Download into the project's js directory curl -o js/gmAppSdk.js https://down-gmb.oss-cn-zhangjiakou.aliyuncs.com/appWebJs/gmAppSdk.jsImport the local file in your HTML:
<script src="./js/gmAppSdk.js"></script>
Using the SDK
After it is imported, the GM SDK is attached to the global variable window.$gm. You can use the full API the SDK provides as follows:
// Check whether the SDK loaded successfully
if (window.$gm) {
console.log('GM SDK 加载成功');
// Call an SDK method
window.$gm.methodName();
} else {
console.error('GM SDK 加载失败');
}Option 2: install with npm
Install the dependency
Install gm-app-sdk with npm or yarn:
npm install gm-app-sdk
# or
yarn add gm-app-sdkImport the SDK
Import gm-app-sdk into your project:
import gmAppSdk from 'gm-app-sdk';Integrate the SDK
Important: to avoid unexpected errors, always import gm-app-sdk on the first line of your entry file.
// main.js - import on the first line of the file
import 'gm-app-sdk';
import { createApp } from 'vue';
import App from './App.vue';
const app = createApp(App);
app.mount('#app');TypeScript support
If your project uses TypeScript, you can add type definitions for a better development experience:
Step 1: create a type declaration file
Create or edit the global.d.ts file in your project root:
// global.d.ts - extend the global Window interface
import { GMProps } from 'gm-app-sdk';
declare global {
interface Window {
$gm: GMProps;
}
}
export {};Step 2: configure TypeScript
Make sure the type declaration file is included in tsconfig.json:
{
"compilerOptions": {
"types": ["gm-app-sdk"]
},
"include": [
"src/**/*",
"global.d.ts"
]
}Example
With the configuration above in place, you can use the features the SDK provides:
// Use inside a Vue component
export default {
mounted() {
// Access GM SDK features
if (window.$gm) {
console.log('GM SDK 已成功加载');
// Call a method the SDK provides
window.$gm.someMethod();
}
}
}Notes
- Load order: import the SDK at the earliest stage of your app.
- Compatibility: make sure your build tool supports ES6 module imports.
- Type safety: when you use TypeScript, configure type declarations for a better development experience.
