A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
desktop: add support for automatic updates
Abdullah Atta13b8580b2fe9
diff --git a/apps/desktop/scripts/build.mjs b/apps/desktop/scripts/build.mjsindex c66e94b4e..a36dc80ab 100644--- a/apps/desktop/scripts/build.mjs+++ b/apps/desktop/scripts/build.mjs@@ -42,17 +42,18 @@ const sodiumNativePrebuildPath = (arch) =>`${os.platform()}-${arch}`);const webAppPath = path.resolve(path.join(__dirname, "..", "..", "web"));-if (args.rebuild) {- await fs.rm("./build/", { force: true, recursive: true });- await exec(`cd ${webAppPath} && npm run build:desktop`);+await fs.rm("./build/", { force: true, recursive: true });- await fs.cp(path.join(webAppPath, "build"), "build", {- recursive: true,- force: true- });+if (args.rebuild || !existsSync(path.join(webAppPath, "build"))) {+ await exec(`cd ${webAppPath} && npm run build:desktop`);}+await fs.cp(path.join(webAppPath, "build"), "build", {+ recursive: true,+ force: true+});+if (args.variant === "mas") {await exec(`npm run bundle:mas`);} else {diff --git a/apps/desktop/src/api/updater.ts b/apps/desktop/src/api/updater.tsindex 50094e334..7c6215b5d 100644--- a/apps/desktop/src/api/updater.ts+++ b/apps/desktop/src/api/updater.ts@@ -21,6 +21,8 @@ import { initTRPC } from "@trpc/server";import { observable } from "@trpc/server/observable";import { CancellationToken, autoUpdater } from "electron-updater";import type { AppUpdaterEvents } from "electron-updater/out/AppUpdater";+import { z } from "zod";+import { config } from "../utils/config";type UpdateInfo = { version: string };type Progress = { percent: number };@@ -28,6 +30,7 @@ type Progress = { percent: number };const t = initTRPC.create();export const updaterRouter = t.router({+ autoUpdates: t.procedure.query(() => config.automaticUpdates),install: t.procedure.query(() => autoUpdater.quitAndInstall()),download: t.procedure.query(async () => {const cancellationToken = new CancellationToken();@@ -37,6 +40,13 @@ export const updaterRouter = t.router({await autoUpdater.checkForUpdates();}),+ toggleAutoUpdates: t.procedure+ .input(z.boolean().optional())+ .mutation(({ input }) => {+ config.automaticUpdates =+ input === undefined ? !config.automaticUpdates : input;+ }),+onChecking: createSubscription("checking-for-update"),onDownloaded: createSubscription<"update-downloaded", UpdateInfo>("update-downloaded"diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.tsindex 0a36dd539..352799154 100644--- a/apps/desktop/src/main.ts+++ b/apps/desktop/src/main.ts@@ -34,10 +34,6 @@ import { router, api } from "./api";import { config } from "./utils/config";import path from "path";-if (!RELEASE) {- require("electron-reloader")(module);-}-if (process.platform == "win32" && process.env.PORTABLE_EXECUTABLE_DIR) {console.log("Portable app: true");const root = path.join(process.env.PORTABLE_EXECUTABLE_DIR, "Notesnook");diff --git a/apps/desktop/src/utils/autoupdater.ts b/apps/desktop/src/utils/autoupdater.tsindex 357834626..c04f8562b 100644--- a/apps/desktop/src/utils/autoupdater.ts+++ b/apps/desktop/src/utils/autoupdater.ts@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/import { autoUpdater } from "electron-updater";+import { config } from "./config";async function configureAutoUpdater() {autoUpdater.setFeedURL({@@ -26,7 +27,7 @@ async function configureAutoUpdater() {useMultipleRangeRequest: false});- autoUpdater.autoDownload = false;+ autoUpdater.autoDownload = config.automaticUpdates;autoUpdater.allowDowngrade = false;autoUpdater.allowPrerelease = false;autoUpdater.autoInstallOnAppQuit = true;diff --git a/apps/desktop/src/utils/config.ts b/apps/desktop/src/utils/config.tsindex 83bbf1bb9..6d938ab13 100644--- a/apps/desktop/src/utils/config.ts+++ b/apps/desktop/src/utils/config.ts@@ -40,7 +40,8 @@ export const config = {privacyMode: false,isSpellCheckerEnabled: false,zoomFactor: 0,- theme: nativeTheme.themeSource+ theme: nativeTheme.themeSource,+ automaticUpdates: true};type ConfigKey = keyof typeof config;diff --git a/apps/web/src/dialogs/settings/behaviour-settings.ts b/apps/web/src/dialogs/settings/behaviour-settings.tsindex 01c4c3419..1f1bebbd8 100644--- a/apps/web/src/dialogs/settings/behaviour-settings.ts+++ b/apps/web/src/dialogs/settings/behaviour-settings.ts@@ -134,5 +134,27 @@ export const BehaviourSettings: SettingsGroup[] = []}]+ },+ {+ key: "updates",+ section: "behaviour",+ header: "Updates",+ settings: [+ {+ key: "auto-updates",+ title: "Automatic updates",+ description:+ "Automatically download & install updates in the background without prompting first.",+ onStateChange: (listener) =>+ useSettingStore.subscribe((s) => s.autoUpdates, listener),+ components: [+ {+ type: "toggle",+ isToggled: () => useSettingStore.getState().autoUpdates,+ toggle: () => useSettingStore.getState().toggleAutoUpdates()+ }+ ]+ }+ ]}];diff --git a/apps/web/src/stores/setting-store.js b/apps/web/src/stores/setting-store.jsindex 194f95dae..e36b2bbaa 100644--- a/apps/web/src/stores/setting-store.js+++ b/apps/web/src/stores/setting-store.js@@ -53,6 +53,7 @@ class SettingStore extends BaseStore {* @type {DesktopIntegrationSettings | undefined}*/desktopIntegrationSettings = undefined;+ autoUpdates = true;refresh = async () => {this.set({@@ -63,7 +64,8 @@ class SettingStore extends BaseStore {desktopIntegrationSettings:await desktop?.integration.desktopIntegration.query(),privacyMode: await desktop?.integration.privacyMode.query(),- zoomFactor: await desktop?.integration.zoomFactor.query()+ zoomFactor: await desktop?.integration.zoomFactor.query(),+ autoUpdates: await desktop?.updater.autoUpdates.query()});};@@ -160,6 +162,12 @@ class SettingStore extends BaseStore {this.set({ privacyMode: !privacyMode });await desktop?.integration.setPrivacyMode.mutate(!privacyMode);};++ toggleAutoUpdates = async () => {+ const autoUpdates = this.get().autoUpdates;+ this.set({ autoUpdates: !autoUpdates });+ await desktop?.updater.toggleAutoUpdates.mutate(!autoUpdates);+ };}const [useStore, store] = createStore(SettingStore);