diff --git a/forge.config.js b/forge.config.js index 3d5d767..f3feea9 100644 --- a/forge.config.js +++ b/forge.config.js @@ -1,5 +1,6 @@ module.exports = { packagerConfig: { + asar: true, icon: './images/icon' }, rebuildConfig: {}, @@ -26,7 +27,13 @@ module.exports = { options: { icon: './images/icon.png' } - }, + } + }, + ], + plugins: [ + { + name: '@electron-forge/plugin-auto-unpack-natives', + config: {}, }, - ] + ], }; diff --git a/js/script.js b/js/script.js index c1ed43d..baac638 100644 --- a/js/script.js +++ b/js/script.js @@ -6,13 +6,13 @@ const Store = require('electron-store'); const store = new Store() // DOM -let slackTokenText = document.querySelector("#i-slack-token") -let saveButton = document.querySelector("#b-save") -let dndAddAnotherButton = document.querySelector("#b-dnd-set") -let statusAddAnotherButton = document.querySelector("#b-status-set") -let generateSlackTokenButton = document.querySelector("#generate-slack-token") -let appVersionText = document.querySelector("#app-version") -let downloadsButton = document.querySelector("#downloads") +const slackTokenText = document.querySelector("#i-slack-token") +const saveButton = document.querySelector("#b-save") +const dndAddAnotherButton = document.querySelector("#b-dnd-set") +const statusAddAnotherButton = document.querySelector("#b-status-set") +const generateSlackTokenButton = document.querySelector("#generate-slack-token") +const appVersionText = document.querySelector("#app-version") +const downloadsButton = document.querySelector("#downloads") // slack token read / store messaging @@ -20,6 +20,13 @@ ipcRenderer.invoke("read-slack-token").then((token) => { if (token != "") slackTokenText.value = "●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●" }) + +ipcRenderer.on("auto-minimise", () => { + const abortFunction = startCountdown() + document.addEventListener("mousemove", abortFunction) +}) + + slackTokenText.addEventListener("keyup", function (event) { if (slackTokenText.value != "●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●") ipcRenderer.send("store-slack-token", slackTokenText.value) @@ -346,4 +353,49 @@ function checkIfShortcutIsTaken(key, section, type, index) { return taken } +function startCountdown() { + const autoMinimseAlert = document.createElement("div") + autoMinimseAlert.id = "alert" + autoMinimseAlert.classList.add("alert", "alert-primary") + autoMinimseAlert.role = "alert" + // Set initial styles for the transition + autoMinimseAlert.style.opacity = "0"; + autoMinimseAlert.style.transition = "opacity 0.5s ease-in-out"; + document.querySelector("body").prepend(autoMinimseAlert); + // Trigger reflow to apply initial styles + autoMinimseAlert.offsetHeight; + // Set final styles to start the transition + autoMinimseAlert.style.opacity = "1"; + + let count = 3; + // Initial call to start the countdown + let timeoutId + updateCountdown() + + function updateCountdown() { + autoMinimseAlert.textContent = `Minimising to system tray in ${count}`; + + if (count === -1) { + autoMinimseAlert.textContent = "Auto minimising now" + autoMinimseAlert.remove() + ipcRenderer.send("minimise") + } + else { + // Continue the countdown + count-- + // Schedule the next update after 1 second + timeoutId = setTimeout(updateCountdown, 1000) + } + } + + // Function to abort the countdown + function abortCountdown() { + clearTimeout(timeoutId) + autoMinimseAlert.remove() + } + + // Return the function to allow external abortion + return abortCountdown +} + diff --git a/main.js b/main.js index 97fccf4..af2eaf4 100644 --- a/main.js +++ b/main.js @@ -12,7 +12,7 @@ var autoLauncher = new AutoLaunch({ // Checking if autoLaunch is enabled, if not then enabling it. autoLauncher.isEnabled().then(function (isEnabled) { if (isEnabled) return; - autoLauncher.enable(); slackTokenInputField.value + autoLauncher.enable(); }).catch(function (err) { throw err; }); @@ -32,9 +32,6 @@ const contextMenu = Menu.buildFromTemplate([ app.dock.show() } mainWindow.show() - mainWindow.webContents.once("dom-ready", function () { - mainWindow.webContents.send("read-slack-token", readToken()) - }) } }, { @@ -53,10 +50,18 @@ app.whenReady().then(() => { loadDefaultValues() mainWindow = createWindow() + mainWindow.webContents.once("dom-ready", function () { + if (readToken() != "") + mainWindow.webContents.send("auto-minimise") + }) app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) { mainWindow = createWindow() + mainWindow.webContents.once("dom-ready", function () { + if (readToken() != "") + mainWindow.webContents.send("auto-minimise") + }) } }) @@ -399,13 +404,12 @@ function checkForUpdates() { ) .then((response) => response.json()) .then((result) => { - if (result.version > app.getVersion()) { + if (result.version != app.getVersion()) { new Notification({ title: `New update available!`, body: `Click on downloads link in the app` }).show(); } - }) .catch((err) => { console.log(err); diff --git a/package.json b/package.json index 5119f09..8976fa7 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,12 @@ "make": "electron-forge make" }, "devDependencies": { - "@electron-forge/cli": "^6.1.1", - "@electron-forge/maker-deb": "^6.1.1", - "@electron-forge/maker-rpm": "^6.1.1", - "@electron-forge/maker-squirrel": "^6.1.1", - "@electron-forge/maker-zip": "^6.1.1", + "@electron-forge/cli": "^7.2.0", + "@electron-forge/maker-deb": "^7.2.0", + "@electron-forge/maker-rpm": "^7.2.0", + "@electron-forge/maker-squirrel": "^7.2.0", + "@electron-forge/maker-zip": "^7.2.0", + "@electron-forge/plugin-auto-unpack-natives": "^7.2.0", "electron": "^24.0.0" }, "dependencies": { @@ -24,4 +25,4 @@ "electron-squirrel-startup": "^1.0.0", "electron-store": "^8.1.0" } -} \ No newline at end of file +} diff --git a/style.css b/style.css index d75a240..88353af 100644 --- a/style.css +++ b/style.css @@ -42,6 +42,11 @@ body { color: var(--font); } +.alert { + text-align: center; + padding: 0.25rem; +} + p { margin-bottom: 0; color: var(--font);