dock.js 2.2 KB
Newer Older
郭维嘉 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
import { dialog, Menu, Tray, app, shell } from "electron";
import path from "path";
import pkg from "../../package.json";
import os from "os";
import { commonConst } from "./common/utils";

function createDock(window) {
  return new Promise((resolve, reject) => {
    let icon;
    if (commonConst.macOS()) {
      icon = "./rocket.png";
    } else if (commonConst.windows()) {
      icon = parseInt(os.release()) < 10 ? "./icon@2x.png" : "./icon.ico";
    } else {
      icon = "icon@2x.png";
    }
    const appIcon = path.join(__static, icon);
    const dockMenu = Menu.buildFromTemplate([
      {
        label: "注册",
        click() {
          shell.openExternal("https://passport.csdn.net/newlogin?code=mobile");
        }
      },  
      {
        label: "帮助文档",
        click: () => {
          process.nextTick(() => {
            shell.openExternal(
              "https://yre5673znb.feishu.cn/docs/doccnMnLv3iZ3epFvjXprnPum3b"
            );
          });
        }
      },
      {
        label: "意见反馈",
        click: () => {
          process.nextTick(() => {
            shell.openExternal("https://www.wenjuan.com/s/UZBZJvmzhg/");
          });
        }
      },
      { type: "separator" },
      {
        label: "显示窗口",
        accelerator: "Alt+R",
        click() {
          window.show();
        }
      },
      {
        label: "偏好设置",
        click() {
          window.show();
          window.webContents.send("tray-setting");
        }
      },
      {
        label: "关于",
        click() {
          dialog.showMessageBox({
            title: "Quicker",
            message: "即刻",
            detail: `Version: ${pkg.version}\nAuthor: libai`
          });
        }
      },
      { type: "separator" },
      {
        label: "重启",
        click() {
          app.relaunch();
          app.quit();
        }
      },
      {
        role: "quit",
        label: "退出"
      }
    ]);
    // appIcon.on("click", () => {
    //   appIcon.popUpContextMenu(contextMenu);
    // });
    // appIcon.setContextMenu(contextMenu);

    // resolve(appIcon);
    app.dock.setMenu(dockMenu);
    app.dock.setIcon(appIcon);

    resolve(app);
  });
}

export default createDock;