Skip to content

Commit

Permalink
enh(updater): add updates channels
Browse files Browse the repository at this point in the history
  • Loading branch information
eythaann committed Oct 14, 2024
1 parent a43edf6 commit 582d5a9
Show file tree
Hide file tree
Showing 154 changed files with 934 additions and 214 deletions.
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

### enhancements
- improve open_file function to allow arguments.
- allow to users select update channel between release, beta and nightly.

### fix
- not getting icons directly from .lnk files
- not getting icons directly from .lnk files.
- users not recieving update notification on settings header.

## [2.0.0]
### breaking changes
Expand Down
35 changes: 30 additions & 5 deletions documentation/schemas/settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,6 @@
}
]
},
"betaChannel": {
"description": "enable experimental/beta updates",
"default": false,
"type": "boolean"
},
"dateFormat": {
"description": "MomentJS date format",
"default": "ddd D MMM, hh:mm A",
Expand Down Expand Up @@ -400,6 +395,17 @@
"type": "string"
}
},
"updater": {
"description": "Updater Settings",
"default": {
"channel": "Release"
},
"allOf": [
{
"$ref": "#/definitions/UpdaterSettings"
}
]
},
"virtualDesktopStrategy": {
"description": "what virtual desktop implementation will be used, in case Native is not available we use Seelen",
"default": "Native",
Expand Down Expand Up @@ -1487,6 +1493,25 @@
"Bottom"
]
},
"UpdateChannel": {
"type": "string",
"enum": [
"Release",
"Beta",
"Nightly"
]
},
"UpdaterSettings": {
"type": "object",
"required": [
"channel"
],
"properties": {
"channel": {
"$ref": "#/definitions/UpdateChannel"
}
}
},
"VirtualDesktopStrategy": {
"type": "string",
"enum": [
Expand Down
22 changes: 21 additions & 1 deletion lib/src/handlers/invokers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { invoke as tauriInvoke, InvokeArgs, InvokeOptions } from '@tauri-apps/api/core';

export enum SeelenCommand {
// General
Run = 'run',
Expand All @@ -13,6 +15,9 @@ export enum SeelenCommand {
GetIcon = 'get_icon',
GetSystemColors = 'get_system_colors',
SimulateFullscreen = 'simulate_fullscreen',
CheckForUpdates = 'check_for_updates',
/** Restart the app after install the update so it returns a promise resolved with `never` */
InstallLastAvailableUpdate = 'install_last_available_update',

// Seelen Settings
SetAutoStart = 'set_auto_start',
Expand Down Expand Up @@ -73,4 +78,19 @@ export enum SeelenCommand {
// Notifications
NotificationsClose = 'notifications_close',
NotificationsCloseAll = 'notifications_close_all',
}
}

type ReturnTypeByCommand = Record<SeelenCommand, unknown> & {
[SeelenCommand.CheckForUpdates]: boolean;
[SeelenCommand.InstallLastAvailableUpdate]: never;
};

export type SeelenCommandReturn<T extends SeelenCommand> = ReturnTypeByCommand[T];

export async function invoke<T extends SeelenCommand>(
command: T,
args?: InvokeArgs,
options?: InvokeOptions,
): Promise<SeelenCommandReturn<T>> {
return tauriInvoke(command, args, options);
}
29 changes: 26 additions & 3 deletions lib/src/state/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,29 @@ impl Default for AhkVarList {
}
}

// ========================== Seelen Updates ==============================

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub enum UpdateChannel {
Release,
Beta,
Nightly,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct UpdaterSettings {
pub channel: UpdateChannel,
}

impl Default for UpdaterSettings {
fn default() -> Self {
Self {
channel: UpdateChannel::Release,
}
}
}

// ======================== Final Settings Struct ===============================

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
Expand Down Expand Up @@ -504,8 +527,8 @@ pub struct Settings {
pub date_format: String,
/// what virtual desktop implementation will be used, in case Native is not available we use Seelen
pub virtual_desktop_strategy: VirtualDesktopStrategy,
/// enable experimental/beta updates
pub beta_channel: bool,
/// Updater Settings
pub updater: UpdaterSettings,
}

impl Default for Settings {
Expand All @@ -525,7 +548,7 @@ impl Default for Settings {
language: Some(Self::get_system_language()),
date_format: "ddd D MMM, hh:mm A".to_owned(),
virtual_desktop_strategy: VirtualDesktopStrategy::Native,
beta_channel: false,
updater: UpdaterSettings::default(),
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion lib/src/state/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ export class SeelenLauncherSettings {
runners: SeelenLauncherRunner[] = [];
}

export enum UpdateChannel {
Release = 'Release',
Beta = 'Beta',
Nightly = 'Nightly',
}

export class UpdaterSettings {
channel: UpdateChannel = UpdateChannel.Nightly;
}

export class Settings extends Obtainable<Settings>(
SeelenCommand.StateGetSettings,
SeelenEvent.StateSettingsChanged,
Expand All @@ -73,7 +83,7 @@ export class Settings extends Obtainable<Settings>(
language: string = '';
dateFormat: string = 'ddd D MMM, hh:mm A';
virtualDesktopStrategy: VirtualDesktopStrategy = VirtualDesktopStrategy.Native;
betaChannel: boolean = false;
updater: UpdaterSettings = new UpdaterSettings();
}

export class FancyToolbarSettings {
Expand Down
42 changes: 42 additions & 0 deletions src/apps/settings/components/header/UpdateButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Badge, Button, Tooltip } from 'antd';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { invoke, SeelenCommand } from 'seelen-core';

import { Icon } from 'src/apps/shared/components/Icon';

export function UpdateButton() {
const [downloading, setDownloading] = useState<boolean>(false);
const [update, setUpdate] = useState<boolean>(false);

const { t } = useTranslation();

useEffect(() => {
invoke(SeelenCommand.CheckForUpdates)
.then(setUpdate)
.catch(() => setUpdate(false));
}, []);

if (!update) {
return null;
}

return (
<Tooltip title={downloading ? t('update.downloading') : t('update.available')}>
<Button
type="text"
loading={downloading}
onClick={() => {
if (!downloading) {
setDownloading(true);
invoke(SeelenCommand.InstallLastAvailableUpdate).finally(() => setDownloading(false));
}
}}
>
<Badge dot>
<Icon iconName="TbDownload" />
</Badge>
</Button>
</Tooltip>
);
}
36 changes: 3 additions & 33 deletions src/apps/settings/components/header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
import { invoke } from '@tauri-apps/api/core';
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow';
import { relaunch } from '@tauri-apps/plugin-process';
import { check as getUpdate, Update } from '@tauri-apps/plugin-updater';
import { Badge, Button, Tooltip } from 'antd';
import { useEffect, useState } from 'react';
import { Button, Tooltip } from 'antd';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';
import { SeelenCommand } from 'seelen-core';

import { SaveStore } from '../../modules/shared/store/infra';
import { useAppSelector } from '../../modules/shared/utils/infra';

import { RootActions } from '../../modules/shared/store/app/reducer';
import { RootSelectors } from '../../modules/shared/store/app/selectors';
import { wasInstalledUsingMSIX } from 'src/apps/shared';
import { Icon } from 'src/apps/shared/components/Icon';

import { RouteExtraInfo } from '../navigation/routes';
import { UpdateButton } from './UpdateButton';
import cs from './index.module.css';

export const Header = () => {
let [update, setUpdate] = useState<Update | null>(null);

let route = useAppSelector(RootSelectors.route);
let hasChanges = useAppSelector(RootSelectors.toBeSaved);
let shouldRestart = useAppSelector(RootSelectors.toBeRestarted);
Expand All @@ -30,21 +23,6 @@ export const Header = () => {

const dispatch = useDispatch();

useEffect(() => {
async function checkUpdate() {
let isDev = await invoke<boolean>(SeelenCommand.IsDevMode);
let isMsix = await wasInstalledUsingMSIX();
if (!isDev && !isMsix) {
let update = await getUpdate();
if (update) {
await update.download();
setUpdate(update);
}
}
}
checkUpdate();
}, []);

const cancelChanges = () => {
dispatch(RootActions.restoreToLastLoaded());
};
Expand Down Expand Up @@ -72,15 +50,7 @@ export const Header = () => {
)}
</div>
<div className={cs.actions}>
{update && (
<Tooltip title={t('update.available')}>
<Button type="text" onClick={() => update?.install()}>
<Badge dot>
<Icon iconName="TbDownload" />
</Badge>
</Button>
</Tooltip>
)}
<UpdateButton />
<Button
style={{ minWidth: 60 }}
children={t('cancel')}
Expand Down
10 changes: 8 additions & 2 deletions src/apps/settings/i18n/translations/af.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,16 @@ shortcuts:
focus_latest: Fokus nuut
switch_workspace_0: Skakel oor na werkruimte 1
switch_workspace_1: Skakel oor na Workspace 2
misc_open_settings: Open instellings
toggle_launcher: Toogle
misc_toggle_lock_tracing: Wisselslotopsporing (logs)
misc_toggle_win_event_tracing: Skakel wen -byeenkomsopsporing (logs)
enable: Aktiveer geïntegreerde kortpaaie (AHK)
enable_tooltip: >-
Deaktiveer as u u eie kortpaaie sal implementeer met behulp van die Seelen
Core API
reset: Herstel na standaard
readonly_tooltip: Dit is 'n leesalleen kortpad
open: Oopmaak
loading: Laai ...
save: Red
Expand All @@ -214,8 +219,6 @@ vd:
Inheemse virtuele tafelrekenaarstrategie is nie beskikbaar vir u Windows
-weergawe nie.
save_and_restart: Stoor en herbegin
beta_channel:
enable: Aktiveer beta -kanaal (slegs via GitHub)
monitors_configurations:
label: Monitor {{index}}
wall:
Expand All @@ -236,3 +239,6 @@ inherit: Erf
close: Dig
update:
available: Opdatering beskikbaar!
downloading: Aflaai ...
channel: Update Channel
miscellaneous: Verskillend
10 changes: 8 additions & 2 deletions src/apps/settings/i18n/translations/am.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,14 @@ shortcuts:
decrease_width: ስፋት መቀነስ
switch_workspace_1: ወደ የሥራ ቦታ 2 ቀይር
switch_workspace_0: ወደ የሥራ ቦታ 1 ቀይር
misc_open_settings: ክፍት ቅንብሮች
misc_toggle_lock_tracing: መቆለፊያ መቆለፊያ (ምዝግብ ማስታወሻዎች)
toggle_launcher: ሻይ
misc_toggle_win_event_tracing: የ UNSCUCT PORTERSERSESTERE (ምዝግብ ማስታወሻዎች)
enable: የተቀናጁ አቋራጮችን (AHK)
enable_tooltip: የእራስዎን አቋራጮዎች ​​የሚተገበሩትን የእራስዎን አቋራጮች የሚተገበሩ ከሆነ ያሰናክሉ
reset: ወደ ነባሪዎች ዳግም ያስጀምሩ
readonly_tooltip: ይህ የተነበበ ብቻ አቋራጭ ነው
inProgress: በሂደት ላይ...
open: ክፈት
cancel: ይቅር
Expand All @@ -207,8 +212,6 @@ vd:
native: ተወላጅ
disabled_windows_version: ቤተኛ ምናባዊ ዴስክቶፕ ስትራቴጂ ለዊንዶውስ ስሪትዎ አይገኝም.
save_and_restart: አስቀምጥ & እንደገና ያስጀምሩ
beta_channel:
enable: የቤታ ጣቢያን ያንቁ (በጊትብሎክ ብቻ)
monitors_configurations:
label: ይቆጣጠሩ {{አው.ፊ.}}}}
wall:
Expand All @@ -229,3 +232,6 @@ inherit: ውርስ
close: ገጠመ
update:
available: ዝመና ይገኛል!
downloading: ማውረድ ...
channel: ጣቢያውን አዘምን
miscellaneous: ልዩነቶች
10 changes: 8 additions & 2 deletions src/apps/settings/i18n/translations/ar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,19 @@ shortcuts:
send_to_workspace_9: أرسل إلى مساحة العمل 9
switch_workspace_1: التبديل إلى مساحة العمل 2
switch_workspace_0: التبديل إلى مساحة العمل 1
misc_toggle_lock_tracing: تبديل قفل تتبع (سجلات)
misc_toggle_win_event_tracing: تبديل الفوز تتبع حدث (سجلات)
misc_open_settings: فتح الإعدادات
toggle_launcher: دبليو
reset: إعادة ضبط على الافتراضات
readonly_tooltip: هذا اختصار للقراءة فقط
vd:
strategy:
native: محلي
seelen: سيلين
label: استراتيجية سطح المكتب الظاهري
disabled_windows_version: استراتيجية سطح المكتب الافتراضية الأصلية غير متوفرة لإصدار Windows الخاص بك.
save_and_restart: حفظ وإعادة التشغيل
beta_channel:
enable: تمكين قناة بيتا (فقط عبر جيثب)
monitors_configurations:
label: شاشة {{index}}
wall:
Expand All @@ -230,3 +233,6 @@ inherit: ورث
close: يغلق
update:
available: تحديث متاح!
channel: تحديث قناة
downloading: تنزيل ...
miscellaneous: متنوع
Loading

0 comments on commit 582d5a9

Please sign in to comment.