Skip to content

Commit

Permalink
Update notification
Browse files Browse the repository at this point in the history
  • Loading branch information
FlucTuAteDev committed Sep 3, 2021
1 parent 733120e commit 5e70d82
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 81 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"name": "scheduler",
"version": "0.1.1",
"version": "0.1.4",
"private": true,
"repository": {
"type" : "git",
"url" : "https://github.com/tomikland/scheduler.git"
},
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
<title>Beosztáskezelő</title>
</head>
<body>
<noscript>
Expand Down
33 changes: 20 additions & 13 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<script lang="ts">
import Vue from "vue";
import Snackbar from "@/components/Snackbar.vue";
import UpdateNotification from "./components/UpdateNotification.vue";
import { ipcRenderer } from "electron";
import { debounce } from "lodash";
import replaceTemplate from "@/utils/sheet-to-xlsx"
import parseWithTemplate from "@/utils/xlsx-to-sheet"
import { bufferToWorkbook } from "@/utils/xlsx-helpers"
import { version } from "process";
export default Vue.extend({
name: "App",
components: {
Snackbar
Snackbar,
UpdateNotification
},
data: () => ({
zoomLevel: 100,
Expand All @@ -20,22 +23,23 @@ export default Vue.extend({
routes:
[["Munkalapok", "/setup", "mdi-file-document-multiple"],
["Szerkesztő", "/", "mdi-table-edit"],
["Dolgozók", "/staff", "mdi-account"]]
["Dolgozók", "/staff", "mdi-account"]],
version: ""
}),
created() {
this.hide = debounce(() => { this.snackbar = false }, this.timeout);
ipcRenderer.on("export-query", async (_, templateBuffer: Buffer, path : string) => {
ipcRenderer.on("export-query", async (_, templateBuffer: Buffer, path: string) => {
let workbook = await bufferToWorkbook(templateBuffer)
let template = workbook.worksheets[0]
replaceTemplate(template, this.$store.state.sheets.sheet)
let outBuffer = await workbook.xlsx.writeBuffer()
ipcRenderer.send("export-reply", outBuffer, path)
})
ipcRenderer.on("export-done", (_, path :string, error : Error | undefined) => {
if(error) return console.error(error)
this.$store.commit("log_export", {sheet : this.$store.state.sheets.sheet, path})
ipcRenderer.on("export-done", (_, path: string, error: Error | undefined) => {
if (error) return console.error(error)
this.$store.commit("log_export", { sheet: this.$store.state.sheets.sheet, path })
})
ipcRenderer.on("import-query", async (_, templateBuffer: Buffer, targetBuffer: Buffer) => {
Expand All @@ -52,6 +56,9 @@ export default Vue.extend({
this.$store.dispatch("load")
},
mounted() {
ipcRenderer.invoke("app_version").then((version) => this.version = version)
},
destroyed() {
ipcRenderer.removeAllListeners("export-query")
}
Expand All @@ -60,9 +67,10 @@ export default Vue.extend({

<template>
<v-app class="app">
<update-notification></update-notification>
<snackbar :visibility="snackbar">
<v-icon class="magnifier" color="white">mdi-magnify</v-icon>
Nagyítás:
Nagyítás:
<br />
{{ zoomLevel }}%
</snackbar>
Expand All @@ -73,8 +81,7 @@ export default Vue.extend({
:key="route"
outlined
@click="$router.push(route)"
:disabled="$router.currentRoute.path == route"
>
:disabled="$router.currentRoute.path == route">
<v-icon class="navbar-icon">{{ icon }}</v-icon>
{{ name }}
</v-btn>
Expand All @@ -85,9 +92,8 @@ export default Vue.extend({
<v-btn
href="https://github.com/vuetifyjs/vuetify/releases/latest"
target="_blank"
text
>
<span class="mr-2">Latest Release</span>
text>
<span class="mr-2">Latest Release {{version}}</span>
<v-icon>mdi-open-in-new</v-icon>
</v-btn>
</v-app-bar>
Expand All @@ -113,7 +119,8 @@ export default Vue.extend({
</style>

<style>
html, body{
html,
body {
overflow: auto !important;
}
</style>
139 changes: 76 additions & 63 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,97 +4,110 @@ import { app, protocol, BrowserWindow, ipcMain, shell } from "electron";
import { autoUpdater } from "electron-updater"
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer"
import zoom from "@/config/zoom";
import initZoom from "@/config/zoom";
import "@/config/appmenu"

const isDevelopment = process.env.NODE_ENV !== "production"
if (isDevelopment) require("dotenv").config()

// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([
{ scheme: "app", privileges: { secure: true, standard: true } },
{ scheme: "app", privileges: { secure: true, standard: true } },
]);

async function createWindow() {
// Create the browser window.
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
// Use pluginOptions.nodeIntegration, leave this alone
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
nodeIntegration: process.env
.ELECTRON_NODE_INTEGRATION as unknown as boolean,
contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
},
});

win.maximize();

if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL as string);
if (!process.env.IS_TEST) win.webContents.openDevTools();
} else {
createProtocol("app");
// Load the index.html when not in development
win.loadURL("app://./index.html");
}

win.once("ready-to-show", () => {
autoUpdater.checkForUpdatesAndNotify()
})

zoom(win);
ipcMain.on("reveal-in-explorer", (_, path: string) => {
shell.showItemInFolder(path)
})
// Create the browser window.
const win = new BrowserWindow({
webPreferences: {
// Use pluginOptions.nodeIntegration, leave this alone
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
nodeIntegration: process.env
.ELECTRON_NODE_INTEGRATION as unknown as boolean,
contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
},
show: false
});

if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL as string);
if (!process.env.IS_TEST) win.webContents.openDevTools();
} else {
createProtocol("app");
// Load the index.html when not in development
win.loadURL("app://./index.html");
}

return win
}

// Quit when all windows are closed.
app.on("window-all-closed", () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== "darwin") {
app.quit();
}
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== "darwin") {
app.quit();
}

});

app.on("activate", () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow();
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on("ready", async () => {
if (isDevelopment && !process.env.IS_TEST) {
// Install Vue Devtools
try {
await installExtension(VUEJS_DEVTOOLS);
} catch (e) {
console.error("Vue Devtools failed to install:", e.toString());
}
}
createWindow();
if (isDevelopment && !process.env.IS_TEST) {
// Install Vue Devtools
try {
await installExtension(VUEJS_DEVTOOLS);
} catch (e) {
console.error("Vue Devtools failed to install:", e.toString());
}
}
ipcMain.handle("app_version", (event) => {
return app.getVersion()
});

const mainWindow = await createWindow();

initZoom(mainWindow);

autoUpdater.checkForUpdatesAndNotify()
autoUpdater.on('update-available', () => {
mainWindow.webContents.send('update-available');
});
autoUpdater.on('update-downloaded', () => {
mainWindow.webContents.send('update-downloaded');
});

ipcMain.on("reveal-in-explorer", (_, path: string) => {
shell.showItemInFolder(path)
})

ipcMain.on("update-install", () => {
autoUpdater.quitAndInstall()
})

mainWindow.maximize();
mainWindow.show();
});

// Exit cleanly on request from parent process in development mode.
if (isDevelopment) {
if (process.platform === "win32") {
process.on("message", (data) => {
if (data === "graceful-exit") {
app.quit();
}
});
} else {
process.on("SIGTERM", () => {
app.quit();
});
}
if (process.platform === "win32") {
process.on("message", (data) => {
if (data === "graceful-exit") {
app.quit();
}
});
} else {
process.on("SIGTERM", () => {
app.quit();
});
}
}
2 changes: 1 addition & 1 deletion src/components/Snackbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default Vue.extend({
div.wrapper {
position: absolute;
bottom: 1vw;
right: 1vw;
left: 1vw;
width: 10vw;
min-width: 10vh;
padding: 0.5vw 1vw;
Expand Down
80 changes: 80 additions & 0 deletions src/components/UpdateNotification.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<script lang="ts">
import { ipcRenderer } from "electron"
import { computed, defineComponent, ref } from '@vue/composition-api'
import { compileFunction } from "vm";
export default defineComponent({
props: {
// show: {
// type: Boolean,
// default: false
// }
},
setup(props, context) {
let show = ref(false)
let downloading = ref(false);
let message = computed(() => {
return downloading.value ?
"Frissítés érhető el. Letöltés folyamatban..." :
"Frissítés kész. A változások újraindítás után lépnek érvénybe."
})
ipcRenderer.on("update-available", () => {
show.value = true
downloading.value = true
})
ipcRenderer.on("update-downloaded", () => {
downloading.value = false
})
let close = () => {
show.value = false
}
let restart = () => {
show.value = false
ipcRenderer.send("update-install")
}
return {
show,
downloading,
message,
close,
restart
}
},
})
</script>

<template>
<v-snackbar right bottom v-model="show" color="white text-center" :timeout="-1">
<div class="wrapper">
<v-progress-circular v-if="downloading" indeterminate color="primary"></v-progress-circular>
{{ message }}
<v-btn text v-if="!downloading" color="success" small @click="restart">
<v-icon left>mdi-restart</v-icon>
Újraindítás
</v-btn>
</div>

<template v-slot:action="{attrs}">
<v-btn plain fab x-small @click="close" v-bind="attrs">
<v-icon color="secondary">mdi-close</v-icon>
</v-btn>
</template>
</v-snackbar>
</template>

<style scoped>
.wrapper {
display: flex;
width: 100%;
align-items: center;
justify-content: space-between;
gap: 10px;
background-color: white;
color: var(--v-secondary-base);
}
</style>
1 change: 0 additions & 1 deletion src/config/sheet-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ ipcMain.on("export-reply", (event, outBuffer: Buffer, path: string) => {
})

ipcMain.on("import-path", (_, path: string) => {
console.log(path)
ImportSheet(path)
})

Expand Down
Loading

0 comments on commit 5e70d82

Please sign in to comment.