Call toast from a component.
Aterr opened this issue · comments
Hello!
Firstly, thank you for this neat plugin.
Sorry for a possibly stupid question, I am a new one to this.
Is there a way to call toast inside vue.js component ?
I am using electron + vue.js and trying to display a toast on vue button click.
I made a file with a function, and it's working great inside background.js file on window load.
But when I am trying to call it inside a vue component I receive an error:
API is only available in Windows.
I would be very pleased if anyone could help me with it.
the function file:
function showNotification(msg: any) {
const toast = require("powertoast");
toast({
message: msg
}).catch((err: any) => console.error(err));
}
export { showNotification }
Vue component:
<template>
<v-container fill-height>
<v-row class="text-center" align="center" justify="center">
<v-btn
@click="getNotification('This is a sample notification message')"
>
{{message}}
</v-btn>
</v-row>
</v-container>
</template>
<script lang="ts">
import Vue from "vue";
import { showNotification } from "../plugins/nodeFunctions"
export default Vue.extend({
name: "Test",
data: () => ({
message: 'Press for notification'
}),
methods: {
getNotification(msg: any): void {
showNotification(msg);
}
}
});
</script>
Thanks in advance!
Here is the code responsible for your error :
"use strict";
const os = require("os");
// ...
if (os.platform() !== "win32") throw "API is only available in Windows.";
Let's get the obvious out of the way ... You are running Windows right ? 🙃
I'm not familiar with Vue.js even less when used with Electron but your issue kinda baffles me ...
I mean how can Vue.js allegedly change the output of os.platform() 😲 ?!
I mean I have no idea at this point just console.log(os.platform()) in the component and let's see what's what.
Figured this out.
I should enable the node integration inside vue config file. Works now like a charm 🙃
Sorry for the stupid concern :)