import app from "@system.app"; import device from "@system.device"; import prompt from "@system.prompt"; import shortcut from "@system.shortcut"; import router from "@system.router"; const SHORT_CUT_FORBIDDEN_INFO = "User forbidden"; // 获取设备信息 const getDeviceInfo = () => { device.getDeviceId({ success: (ret) => { console.log(ret) } }) } //获取是否创建图标 const getShortCut = (fn) =>{ shortcut.hasInstalled({ success: (ret) => { fn(ret); } }) } // 判断用户是否创建图标 const hasCreateShortCut = (isPayPage = false,fn) => { shortcut.hasInstalled({ success: (ret) => { if (!ret) { shortcut.install({ message: "添加【追书云】到桌面,方便下次阅读", success: () => { prompt.showToast("添加成功!"); fn && fn(true); }, fail: (code) => { if (code === SHORT_CUT_FORBIDDEN_INFO && !isPayPage) app.exit(); } }) } } }) } // 右上角菜单点击 const showMenu = () => { const appInfo = app.getInfo(); prompt.showContextMenu({ itemList: ["保存桌面", "关于", "取消"], success: function (ret) { switch (ret.index) { case 0: // 保存桌面 hasCreateShortCut(); break; case 1: // 关于 router.push({ uri: "/views/About", params: { name: appInfo.name, icon: appInfo.icon } }); break; case 2: // 取消 break; default: prompt.showToast({ message: "错误" }); } } }); } export default { shortcut, getDeviceInfo, hasCreateShortCut, showMenu, getShortCut }