如何使用Gulp显示本机弹出窗口

问题描述 投票:0回答:2

我正在开发自动化的Gulp构建过程。我已经创建了一个Gulp任务来创建签名的android APK。现在我想显示一个通知弹出窗口,以便我可以知道我的Android APK已经构建。

有没有办法在Gulp流程中显示原生弹出窗口?

我做了研究,发现了node-notifiergulp-notify模块,但两者都不适合我。请帮忙

根据发布的答案,

我试过跟随,但没有帮助...我没有收到通知。它是否需要Windows Toaster支持...我使用的是Windows 8.1 Pro。

gulp.task('notifier', function(){
    notify('Running from notifier task', 'Everything looks good');
});

function notify(title, message) {
    // Load dependencies
    var path = require('path');
    var notifier = require('node-notifier');
    var notifyOptions = {
        title: title,
        message: message,
        //icon: path.join(__dirname, 'coulson.jpg'), // Absolute path (doesn't work on balloons)
        sound: true, // Only Notification Center or Windows Toasters
        wait: true // Wait with callback, until user action is taken against notification
    };

    // start notifier
    notifier.notify(notifyOptions);
}
notifications gulp
2个回答
1
投票

试试这个:

确保通过再次运行安装来安装它们

安装

npm install path node-notifier --save-dev 

任务

gulp.task('notifier', function(){

    notify('Running from notifier task', 'Everything looks good');
);

通知功能

function notify(title, message) {

    // Load dependencies
    var path = require('path');
    var notifier = require('node-notifier');

    var notifyOptions = {
        title: title,
        message: message,
        icon: path.join(__dirname, 'coulson.jpg'), // Absolute path (doesn't work on balloons)
        sound: true, // Only Notification Center or Windows Toasters
        wait: true // Wait with callback, until user action is taken against notification
    };

    // start notifier
    notifier.notify(notifyOptions);
}

0
投票

提问后这已经太晚了,但我认为在这里记录我的解决方案是件好事。因此,有不同的命令可以显示不同操作系统的本机弹出窗口。

1. Windows

使用命令msg * <Your_Message_Here>,例如msg * Hello World。此弹出窗口在1分钟后自动关闭。

2.iOS

使用该命令

osascript -e 'tell app \"System Events\" to display dialog \"<Your_Message>\" with title \"<Your_Title>\"'"

然后你可以使用节点exec执行这些命令,

var WINDOWS_POPUP = "msg * MESSAGE";
var MAC_POPUP = "osascript -e 'tell app \"System Events\" to display dialog \"MESSAGE\" with title \"SUCCESS\"'";

function execCMD(cmd, cb) {
    exec(cmd,
    {
        cwd: './',
        maxBuffer: 2048 * 2048
    },
    function (err, stdout, stderr) {
        plugins.util.log(stdout);
        plugins.util.log(stderr);
        if (err) {
            cb(err);
        } else {
            cb(null,stdout);
        }
    });
}
/**
 * Rename android apk
 */
gulp.task('copyAPK', function () {
    return gulp.src(APK_PATH)
        .pipe(plugins.if(args.signedAPK, plugins.rename(APK_NAME)))
        .pipe(gulp.dest(releaseDirName + '/Android/'))
        .on('end', function () {
            plugins.util.log(plugins.util.colors.green('Good Job! Your APK is ready at following location : ') + plugins.util.colors.cyan(releaseDirName + '/Android/' + APK_NAME))
            execCMD(WINDOWS_POPUP.replace('MESSAGE', 'Good Job! Your APK is ready at following location : ' + releaseDirName + '/Android/' + APK_NAME), function () {
            })
        });
});

/**
 * Copy generated IPA
 */
gulp.task('copyIPA', function () {
    return gulp.src(IPA_PATH)
        .pipe(plugins.rename(IPA_NAME))
        .pipe(gulp.dest(releaseDirName + '/iOS/'))
        .on('end', function () {
            plugins.util.log(plugins.util.colors.green('Good Job! Your IPA is ready at following location : ') + plugins.util.colors.cyan(releaseDirName + '/iOS/' + IPA_NAME))
            execCMD(MAC_POPUP.replace('MESSAGE', 'Good Job! Your IPA is ready at following location : ' + releaseDirName + '/iOS/' + IPA_NAME), function () {
            })
        });
})

希望这将有助于编写脚本的人:)。

© www.soinside.com 2019 - 2024. All rights reserved.