ff-global
TypeScript icon, indicating that this package has built-in type declarations

4.1.46 • Public • Published

Field Flint 系统全局变量

安装

npm install ff-global -S

引入方法

主进程

import "ff-global/main"

渲染进程

import 'ff-global/renderer'

预注入进程

import 'ff-global/preload'

工具(如果只是用到一部分工具)

import util from 'ff-global/util'

注意:上面的使用方法必须在入口顶端引入,以保证全局使用

使用方法

当上面正确引入后,系统会一个全局变量,主进程为global.ff,渲染进程为window.ff,在使用过程中可以直接使用ff 如判断对象为空对象的方法:ff.util.isEmptyObject({})

主进程

type ValueOf<T> = T[keyof T]

declare global {
	namespace ff {
		type MezzFileType = ValueOf<typeof MezzFileType>
		type MqttStatus = ValueOf<typeof MqttStatus>
		type LiveActionType = ValueOf<typeof LiveActionType>
		//gc全局
		namespace gc {
			type KeyboardShortcut = Gc.KeyboardShortcut
			type Client = Gc.Client
			type Subscribes = Gc.Subscribes
		}
	}
	var ff: {
		MqttStatus: typeof MqttStatus
		LiveActionType: typeof LiveActionType
		env: typeof env
		error: typeof error
		util: Util
		gc: ff.gc.Client
		Ajax: typeof Ajax
		//用户信息 store
		userInfo: User.UserInfo | null
		//cm列表
		cmList: User.CMItem[]
		browsers: { [id: string]: BrowserView } //打开的浏览器集合

		currentBrowserTab?: WebContents //当 前显示的浏览器tab页
		//当前浏览的account
		current_account: null | f2.ServerAccount
		//显示中的窗口
		show_popup: {
			[key: string]: boolean
		}
		//当前的tab页,位置
		$tabId: number
	}

	namespace NodeJS {
		interface Global {
			mainWindow: BrowserWindow
		}
	}
}

渲染进程

declare global {
	namespace Axios {
		type Canceler = C
		type RequestConfig = AxiosRequestConfig
	}

	namespace ff {
		type MezzFileType = ValueOf<typeof MezzFileType>
		type MqttStatus = ValueOf<typeof MqttStatus>
		type LiveActionType = ValueOf<typeof LiveActionType>

		//mqtt全局
		namespace mqtt {
			interface Subs {
				[topic: string]: (...data: any) => void
			}
		}

		//gc全局
		namespace gc {
			type KeyboardShortcut = Gc.KeyboardShortcut
			type Client = Gc.Client
			type IpcTopic = Gc.IpcTopic
			type Subscribes = Gc.Subscribes
		}

		namespace country {
			type CountryBase = CB
			type Country = Co
		}
		namespace linkedin {
			type AccountStatus = LinkedinAccount
			type LiStatData = GetLiStatData
		}
	}
}

declare global {
	var ff: Readonly<{
		env: typeof env
		MezzFileType: typeof MezzFileType //常量,mezz文件类型
		MqttStatus: typeof MqttStatus
		LiveActionType: typeof LiveActionType
		Ajax: typeof Ajax
		util: Util
		error: typeof error
		gc: typeof gc
		mqtt: typeof mqtt
		axios: AxiosStatic
		nameSplit: NameSplit
		dateTime: typeof DateTime
		contactInfo: typeof ContactInfo
		linkedin: Linkedin
		country: CountryClass
		analyzeText: {
			company: AnalyzeText
			contact: AnalyzeText
		}
		crawler: {
			util: CrawlerUtil
			db: CrawlerDb
		}
	}>
}

Dependents (0)

Package Sidebar

Install

npm i ff-global

Weekly Downloads

98

Version

4.1.46

License

ISC

Unpacked Size

572 kB

Total Files

42

Last publish

Collaborators

  • amwtxgt