桌面应用电子版完整开发人员指南--Part 4

目录

前言

1.下载zip

2.创建index.js文件

3.隐藏窗口顶部部分内容

4.右下角图标控制其出现or隐藏

5.点击图标时出现在右下角

6.点击图标时出现位置改变

7.鼠标滑至图标时出现‘Timer App’及右键图标出现Quit,点击可退出

8.点击别的窗口会自动关闭该应用

获取本文代码


前言

     本文为整理记录学习桌面应用电子版完整开发人员指南第4部分的笔记。图片清晰度可能不够高,希望这不影响您的观看体验。如果有任何错误,请随时指出,感谢您的阅读

1.下载zip

链接:https://github.com/StephenGrider/ElectronCode

2.创建index.js文件

const path = require('path');

const { app, BrowserWindow} = electron;

let mainWindow;

app.on('ready', () => {
  mainWindow = new BrowserWindow({
    height: 500,
    width: 300
  });
  mainWindow = loadURL(`file://${__dirname}/src/index.html`)

运行项目(cmd打开两个窗口,一个输入npm run electron,一个输入npm run start)

运行npm run electron

运行npm run start

3.隐藏窗口顶部部分内容

有改动的代码见图示意

完整代码

const path = require('path');

const { app, BrowserWindow} = electron;

let mainWindow;

app.on('ready', () => {
  mainWindow = new BrowserWindow({
    height: 500,
    width: 300,
    frame: false,
    resizable: false
  });
  mainWindow = loadURL(`file://${__dirname}/src/index.html`)

运行项目

4.右下角图标控制其出现or隐藏

有改动的代码见图示意

完整代码

const path = require('path');
const electron = require('electron');

const { app, BrowserWindow, Tray} = electron;

let mainWindow;
let tray;

app.on('ready', () => {
  mainWindow = new BrowserWindow({
    height: 500,
    width: 300,
    frame: false,
    resizable: false,
    show: false
  });
  mainWindow = new MainWindow(`file://${__dirname}/src/index.html`)

  const iconName = process.platform === 'win32' ? 'windows-icon.png' : 'iconTemplate.png';
  const iconPath = path.join(__dirname, `./src/assets/${iconName}`);

  new Tray(iconPath);
  tray.on('click' ,() => {
    if(mainWindow.isVisible()){
        mainwindow.hide();
    } else {
        mainwindow.show();
    }
  })
});

5.点击图标时出现在右下角

有改动的代码见图示意

完整代码

const path = require('path');
const electron = require('electron');

const { app, BrowserWindow, Tray} = electron;

let mainWindow;
let tray;

app.on('ready', () => {
  mainWindow = new BrowserWindow({
    height: 500,
    width: 300,
    frame: false,
    resizable: false,
    show: false
  });
  mainWindow = new MainWindow(`file://${__dirname}/src/index.html`)

  const iconName = process.platform === 'win32' ? 'windows-icon.png' : 'iconTemplate.png';
  const iconPath = path.join(__dirname, `./src/assets/${iconName}`);

  new Tray(iconPath);
  tray.on('click' ,(event, bounds) => {
    const {x, y} = bounds;
    const {height, width } = mainWindow.getBounds();

    if(mainWindow.isVisible()){
        mainwindow.hide();
    } else {
        mainwindow.setBounds({
            x: x- width / 2;
            y: 170,
            height,
            width
    });
    mainWindow.show();
    }
  })
});

运行项目

6.点击图标时出现位置改变

index.js

有改动的代码见图示意

完整代码

const path = require('path');
const electron = require('electron');

const { app, BrowserWindow, Tray} = electron;

let mainWindow;
let tray;

app.on('ready', () => {
  mainWindow = new BrowserWindow({
    height: 500,
    width: 300,
    frame: false,
    resizable: false,
    show: false
  });
  mainWindow = new MainWindow(`file://${__dirname}/src/index.html`)

  const iconName = process.platform === 'win32' ? 'windows-icon.png' : 'iconTemplate.png';
  const iconPath = path.join(__dirname, `./src/assets/${iconName}`);

  new Tray(iconPath);
  tray.on('click' ,(event, bounds) => {
    const {x, y} = bounds;
    const {height, width } = mainWindow.getBounds();

    if(mainWindow.isVisible()){
        mainwindow.hide();
    } else {
        const yPosition = process.platform === 'darwin' ? y : y - height;
        mainwindow.setBounds({
            x: x- width / 2;
            y: yPosition,
            height,
            width
    });
    mainWindow.show();
    }
  })
});

运行项目

7.鼠标滑至图标时出现‘Timer App’及右键图标出现Quit,点击可退出

app文件夹下新建time_tray.js文件

const electron = require('electron');
const { Tray, app, Menu } = electron;

class TimerTray extends Tray {
    constructor(iconPath,mainWindow) {
        super(iconPath);

        this.mainWindow = mainWindow;

        this.setToolTip('Timer App');
        this.on('click', this.onClick.bind(this));
    }

    onClick(event, bounds) {
        const { x, y } = bounds;
        const { height, width } = this.mainWindow.getBounds();

        if (this.mainWindow.isVisible()) {
            this.mainWindow.hide();
        } else {
            const yPosition = process.platform === 'darwin' ? y : y - height;
            this.mainWindow.setBounds({
                x: x - width / 2,
                // y: 170,
                y: yPosition,
                height,
                width
            });
            this.mainWindow.show();
        }

    }

    onRightClick(){
        const menuConfig = Menu.buildFromTemplate([
            {
                label: 'Quit',
                click: () => app.quit()
            }
        ]);

        this.popUpContextMenu(menuConfig);
    }
}

module.exports = TimerTray;

修改index.js文件内容

完整代码

const path = require('path');
const electron = require('electron');
const TimerTray = require('./app/timer_tray');

const { app, BrowserWindow, Tray} = electron;

let mainWindow;
let tray;

app.on('ready', () => {
  mainWindow = new BrowserWindow({
    height: 500,
    width: 300,
    frame: false,
    resizable: false,
    show: false
  });
  mainWindow = new MainWindow(`file://${__dirname}/src/index.html`)

  const iconName = process.platform === 'win32' ? 'windows-icon.png' : 'iconTemplate.png';
  const iconPath = path.join(__dirname, `./src/assets/${iconName}`);
  
  tray = new TimerTray(iconPath,mainWindow);

  new Tray(iconPath);
  tray.on('click' ,(event, bounds) => {
    const {x, y} = bounds;
    const {height, width } = mainWindow.getBounds();

    if(mainWindow.isVisible()){
        mainwindow.hide();
    } else {
        const yPosition = process.platform === 'darwin' ? y : y - height;
        mainwindow.setBounds({
            x: x- width / 2;
            y: yPosition,
            height,
            width
    });
    mainWindow.show();
    }
  })
});

运行项目

8.点击别的窗口会自动关闭该应用

修改index.js文件内容

完整代码

const path = require('path');
const electron = require('electron');
const TimerTray = require('./app/timer_tray');

const { app, BrowserWindow, Tray} = electron;

let mainWindow;
let tray;

app.on('ready', () => {
  mainWindow = new BrowserWindow({
    height: 500,
    width: 300,
    frame: false,
    resizable: false,
    show: false
  });
  mainWindow.loadURL(`file://${__dirname}/src/index.html`)
  mainWindow.on('blur', () => {
    mainWindow.hide();
  });

  const iconName = process.platform === 'win32' ? 'windows-icon.png' : 'iconTemplate.png';
  const iconPath = path.join(__dirname, `./src/assets/${iconName}`);
  
  tray = new TimerTray(iconPath,mainWindow);

  new Tray(iconPath);
  tray.on('click' ,(event, bounds) => {
    const {x, y} = bounds;
    const {height, width } = mainWindow.getBounds();

    if(mainWindow.isVisible()){
        mainwindow.hide();
    } else {
        const yPosition = process.platform === 'darwin' ? y : y - height;
        mainwindow.setBounds({
            x: x- width / 2;
            y: yPosition,
            height,
            width
    });
    mainWindow.show();
    }
  })
});

运行项目

获取本文代码

     见本文顶部

  • 20
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ISA88是一个在制造过程自动化中常用的标准,它被定义为制造和加工自动化应用中的工作流程模型和术语。实际上,这是一系列标准文件,包括Part 1到Part 4。 Part 1(ISA-88.01)标准定义了工作流程模型和术语。这是整个标准的基础,并且为后面的标准提供了一个共同的基础。这一部分还定义了四个关键术语:单元、设备模块、控制模块和操作。这些术语用于描述整个工作流程。这一部分还会对工作流程中使用的其它关键术语进行了解释。 Part 2(ISA-88.02)标准描述了生产工艺过程的概念和模型。这一部分关注生产制造场景,并且详细描述了生产工艺过程中包含的各个单元和设备模块之间的关系。这一部分还描述了每个设备模块中包含的控制模块以及操作。 Part 3(ISA-88.03)标准涵盖了英特诺控制层次模型。控制层次模型将每个控制单元分层,并为每个模块定义了不同的控制功能。这一部分还包括为控制层次模型制定细节设计的建议。 Part 4(ISA-88.04)标准涵盖了物流和等级管理。这一部分着重于被称为“制造流程定义”的概念,对于经常变化的制造流程,该概念非常重要。通过“制造流程定义”,用户可以更容易地了解不同的物流、等级和其他生产工艺详细信息,并以一种更有条理的方式进行管理。 总体而言,ISA88标准系列文件为制造业提供了一个通用的模型,该模型具有广泛的应用,可以应对各种生产场景。这个模型允许制造企业设计、转换和管理制造过程,从而提高生产效率、产能和质量。ISA-88系列标准的使用可能会带来意想不到的结果,包括更简单的审核、更快的问题解决以及制造流程的可追溯性和可重现性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值