diff --git a/dev-app-update.yml b/dev-app-update.yml
new file mode 100644
index 0000000..ee2afb5
--- /dev/null
+++ b/dev-app-update.yml
@@ -0,0 +1,6 @@
+owner: ArisuOngaku
+repo: tabs
+provider: github
+updaterCacheDirName: tabs-updater
+publisherName:
+ - Alice Gaudon
diff --git a/resources/js/index.js b/resources/js/index.js
index d74a3ee..807adc6 100644
--- a/resources/js/index.js
+++ b/resources/js/index.js
@@ -17,12 +17,12 @@ const icons = [];
let services = [];
let selectedService = null;
let statusButton, homeButton, forwardButton, backButton, reloadButton;
-let addButton;
+let addButton, settingsButton;
let emptyPage;
let urlPreview;
-let lastDragPosition;
-let oldActiveService; // For service reordering
+// Service reordering
+let lastDragPosition, oldActiveService;
// Service context menu
function openServiceContextMenu(event, serviceId) {
@@ -380,6 +380,9 @@ document.addEventListener('DOMContentLoaded', () => {
addButton = document.getElementById('add-button');
addButton.addEventListener('click', () => ipcRenderer.send('openServiceSettings', null));
+
+ settingsButton = document.getElementById('settings-button');
+ settingsButton.addEventListener('click', () => ipcRenderer.send('openSettings', null));
});
function setActiveService(serviceId) {
diff --git a/resources/js/settings.js b/resources/js/settings.js
new file mode 100644
index 0000000..1c0b50f
--- /dev/null
+++ b/resources/js/settings.js
@@ -0,0 +1,29 @@
+const {ipcRenderer, remote} = require('electron');
+
+let currentVersion;
+let updateStatus;
+
+ipcRenderer.on('current-version', (e, version) => {
+ currentVersion.innerText = `Version: ${version.version}`;
+});
+
+ipcRenderer.on('updateStatus', (e, available, version) => {
+ if (available) {
+ updateStatus.innerHTML = `A new update is available! Click here to download manually.`;
+ } else {
+ updateStatus.innerText = 'Tabs is up to date.';
+ }
+});
+
+function save() {
+ const formData = new FormData(document.querySelector('form'));
+ remote.getCurrentWindow().close();
+}
+
+document.addEventListener('DOMContentLoaded', () => {
+ currentVersion = document.getElementById('current-version');
+ updateStatus = document.getElementById('update-status');
+
+ ipcRenderer.send('syncSettings');
+ ipcRenderer.send('checkForUpdates');
+});
\ No newline at end of file
diff --git a/resources/settings.html b/resources/settings.html
new file mode 100644
index 0000000..fabb880
--- /dev/null
+++ b/resources/settings.html
@@ -0,0 +1,40 @@
+
+
+
+
+ Service settings
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Updater.js b/src/Updater.js
new file mode 100644
index 0000000..fcfa219
--- /dev/null
+++ b/src/Updater.js
@@ -0,0 +1,36 @@
+import {autoUpdater} from "electron-updater";
+
+export default class Updater {
+ #callback = (available, data) => {
+ console.log('Update:', available, data);
+ };
+
+ constructor() {
+ autoUpdater.autoDownload = false;
+ autoUpdater.on('error', err => {
+ this.#callback(false, err);
+ });
+ autoUpdater.on('update-available', v => {
+ this.#callback(true, v);
+ });
+ autoUpdater.on('update-not-available', () => {
+ this.#callback(false);
+ });
+ }
+
+ /**
+ * @param {Function} callback
+ */
+ checkForUpdates(callback) {
+ this.#callback = callback;
+ autoUpdater.checkForUpdates().then(r => {
+ this.#callback(false, r.updateInfo);
+ }).catch(err => {
+ this.#callback(false, err);
+ });
+ }
+
+ getCurrentVersion() {
+ return autoUpdater.currentVersion;
+ }
+}
\ No newline at end of file
diff --git a/src/main.js b/src/main.js
index 7ab63f2..c9a7abc 100644
--- a/src/main.js
+++ b/src/main.js
@@ -6,11 +6,13 @@ import Meta from "./Meta";
import Config from "./Config";
import Service from "./Service";
import {autoUpdater} from "electron-updater";
+import Updater from "./Updater";
const resourcesDir = path.resolve(__dirname, '../resources');
const iconPath = path.resolve(resourcesDir, 'logo.png');
const config = new Config();
+const updater = new Updater();
const devMode = Meta.isDevMode();
@@ -22,7 +24,7 @@ let selectedService = 0;
let tray;
let window;
-let serviceSettingsWindow;
+let serviceSettingsWindow, settingsWindow;
function toggleMainWindow() {
if (window != null) {
@@ -201,6 +203,49 @@ async function createWindow() {
}
});
+ // Open add service window
+ ipcMain.on('openSettings', (e) => {
+ if (!settingsWindow) {
+ console.log('Opening settings');
+ settingsWindow = new BrowserWindow({
+ webPreferences: {
+ nodeIntegration: true,
+ enableRemoteModule: true,
+ webviewTag: true,
+ },
+ parent: window,
+ modal: true,
+ autoHideMenuBar: true,
+ height: 850,
+ });
+ settingsWindow.on('close', () => {
+ settingsWindow = null;
+ });
+ if (devMode) {
+ settingsWindow.webContents.openDevTools({
+ mode: 'right'
+ });
+ }
+ let syncListener;
+ ipcMain.on('syncSettings', syncListener = () => {
+ settingsWindow.webContents.send('current-version', updater.getCurrentVersion());
+ });
+
+ let checkForUpdatesListener;
+ ipcMain.on('checkForUpdates', checkForUpdatesListener = (e) => {
+ updater.checkForUpdates((available, version) => {
+ ipcMain.emit('updateStatus', available, version);
+ });
+ });
+ settingsWindow.on('close', () => {
+ ipcMain.removeListener('sync-settings', syncListener);
+ ipcMain.removeListener('checkForUpdates', checkForUpdatesListener);
+ });
+ settingsWindow.loadFile(path.resolve(resourcesDir, 'settings.html'))
+ .catch(console.error);
+ }
+ });
+
console.log('> App started');
}