Skip to content

Commit

Permalink
Add auto update setting
Browse files Browse the repository at this point in the history
  • Loading branch information
probablykasper committed Oct 8, 2024
1 parent 7fb91d3 commit 5ce4009
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 27 deletions.
2 changes: 2 additions & 0 deletions ferrum-addon/addon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ export interface ViewOptions {
shownPlaylistFolders: Array<string>
/** Empty is treated as default */
columns: Array<string>
/** Auto update checking */
noAutoUpdate: boolean
skipUpdatingToVersion?: string
}
export declare function load_view_options(): ViewOptions
Expand Down
4 changes: 4 additions & 0 deletions src-native/view_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub struct ViewOptions {
pub shown_playlist_folders: Vec<String>,
/// Empty is treated as default
pub columns: Vec<String>,
/// Auto update checking
#[serde(default)]
pub no_auto_update: bool,
pub skip_updating_to_version: Option<String>,
}
impl ViewOptions {
Expand All @@ -24,6 +27,7 @@ impl ViewOptions {
Err(_) => ViewOptions {
shown_playlist_folders: Vec::new(),
columns: Vec::new(),
no_auto_update: false,
skip_updating_to_version: None,
},
}
Expand Down
15 changes: 14 additions & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import { navigate_back, navigate_forward } from './lib/router'
import './lib/router'
import CheckForUpdates from './components/CheckForUpdates.svelte'
import Settings from './components/Settings.svelte'
ipc_renderer.invoke('app_loaded').catch(() => {
ipc_renderer.invoke('showMessageBox', false, {
Expand Down Expand Up @@ -110,6 +111,15 @@
}
}
let show_settings = false
onDestroy(
ipc_listen('show_settings', () => {
if ($modal_count === 0) {
show_settings = true
}
}),
)
let show_itunes_import = false
onDestroy(
ipc_listen('itunesImport', () => {
Expand Down Expand Up @@ -217,6 +227,7 @@
{/if}
</main>

<QuickNav />
{#if $current_list}
<TrackInfo />
{/if}
Expand All @@ -226,7 +237,9 @@
{#if show_itunes_import}
<ItunesImport cancel={() => (show_itunes_import = false)} />
{/if}
<QuickNav />
{#if show_settings}
<Settings on_close={() => (show_settings = false)} />
{/if}
<CheckForUpdates />

<DragGhost />
Expand Down
6 changes: 4 additions & 2 deletions src/components/CheckForUpdates.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
check()
async function check() {
if (is_dev || !window.navigator.onLine) {
if (!window.navigator.onLine || view_options.noAutoUpdate) {
return
}
const result = await ipc_renderer.invoke('check_for_updates')
Expand Down Expand Up @@ -58,7 +58,9 @@
>
<div class="grow"></div>
<Button secondary autofocus on:click={() => (latest_update = null)}>Later</Button>
<Button on:click={() => ipc_renderer.invoke('open_url', channel.url)}>Update</Button>
<Button type="submit" on:click={() => ipc_renderer.invoke('open_url', channel.url)}
>Update</Button
>
</svelte:fragment>
</Modal>
{/if}
34 changes: 34 additions & 0 deletions src/components/Settings.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script lang="ts">
import Modal from './Modal.svelte'
import Button from './Button.svelte'
import { save_view_options, view_options } from '@/lib/data'
export let on_close: () => void
let auto_update = !view_options.noAutoUpdate
function save() {
view_options.noAutoUpdate = !auto_update
save_view_options(view_options)
on_close()
}
</script>

<Modal on_cancel={on_close} cancel_on_escape form={save} title="Settings">
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<!-- svelte-ignore a11y-autofocus -->
<div class="w-96 text-sm">
<label class="flex items-center gap-2">
<input
type="checkbox"
class="size-3.5 border-gray-300 bg-gray-100 text-blue-600 outline-offset-2 outline-blue-500 outline-solid focus-visible:outline"
bind:checked={auto_update}
/>
Automatically check for updates on startup
</label>
</div>
<svelte:fragment slot="buttons">
<Button secondary on:click={on_close}>Cancel</Button>
<Button type="submit" on:click={save}>Save</Button>
</svelte:fragment>
</Modal>
65 changes: 41 additions & 24 deletions src/electron/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ export function init_menu_bar(app: App, main_window: BrowserWindow) {
submenu: [
{ role: 'about' },
{ type: 'separator' },
{
label: 'Settings...',
accelerator: 'CmdOrCtrl+,',
click() {
web_contents.send('show_settings')
},
},
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
{ role: 'hide' },
Expand All @@ -37,32 +45,41 @@ export function init_menu_bar(app: App, main_window: BrowserWindow) {
{
label: 'New Playlist',
accelerator: 'CmdOrCtrl+N',
click: () => {
click() {
web_contents.send('newPlaylist', 'root', false)
},
},
{
label: 'New Playlist Folder',
click: () => {
click() {
web_contents.send('newPlaylist', 'root', true)
},
},
{ type: 'separator' },
{
label: 'Import...',
accelerator: 'CmdOrCtrl+O',
click: () => {
click() {
web_contents.send('import')
},
},
{ type: 'separator' },
{
label: 'Import iTunes Library...',
click: () => {
click() {
web_contents.send('itunesImport')
},
},
{ type: 'separator' },
{
label: 'Settings...',
accelerator: 'CmdOrCtrl+,',
click() {
web_contents.send('show_settings')
},
visible: !is.mac,
},
{ type: 'separator', visible: !is.mac },
is.mac ? { role: 'close' } : { role: 'quit' },
],
},
Expand All @@ -87,7 +104,7 @@ export function init_menu_bar(app: App, main_window: BrowserWindow) {
menu.push({
label: 'Filter',
accelerator: 'CmdOrCtrl+F',
click: () => {
click() {
web_contents.send('filter')
},
})
Expand All @@ -100,22 +117,22 @@ export function init_menu_bar(app: App, main_window: BrowserWindow) {
{
label: 'Play Next',
accelerator: '',
click: () => {
click() {
web_contents.send('selected_tracks_action', 'Play Next')
},
},
{
label: 'Add to Queue',
accelerator: '',
click: () => {
click() {
web_contents.send('selected_tracks_action', 'Add to Queue')
},
},
{ type: 'separator' },
{
label: 'Get Info',
accelerator: 'CmdOrCtrl+I',
click: () => {
click() {
web_contents.send('selected_tracks_action', 'Get Info')
},
},
Expand All @@ -127,22 +144,22 @@ export function init_menu_bar(app: App, main_window: BrowserWindow) {
else return 'Reveal in File Manager'
})(),
accelerator: 'Shift+CmdOrCtrl+R',
click: () => {
click() {
web_contents.send('selected_tracks_action', 'reveal_track_file')
},
},
{ type: 'separator' },
{
label: 'Remove from Playlist',
accelerator: '',
click: () => {
click() {
web_contents.send('selected_tracks_action', 'Remove from Playlist')
},
},
{
label: 'Delete from Library',
accelerator: 'CmdOrCtrl+Backspace',
click: () => {
click() {
web_contents.send('selected_tracks_action', 'Delete from Library')
},
},
Expand All @@ -156,15 +173,15 @@ export function init_menu_bar(app: App, main_window: BrowserWindow) {
id: 'Show Queue',
type: 'checkbox',
accelerator: 'CmdOrCtrl+U',
click: () => {
click() {
web_contents.send('Show Queue')
},
},
{
label: 'Toggle Quick Nav',
type: 'checkbox',
accelerator: 'CmdOrCtrl+K',
click: () => {
click() {
web_contents.send('ToggleQuickNav')
},
},
Expand Down Expand Up @@ -194,21 +211,21 @@ export function init_menu_bar(app: App, main_window: BrowserWindow) {
{
label: 'Pause',
// no accelerator because it's unreliable
click: () => {
click() {
web_contents.send('playPause')
},
},
{
label: 'Next',
accelerator: 'CmdOrCtrl+Right',
click: () => {
click() {
web_contents.send('Next')
},
},
{
label: 'Previous',
accelerator: 'CmdOrCtrl+Left',
click: () => {
click() {
web_contents.send('Previous')
},
},
Expand All @@ -218,7 +235,7 @@ export function init_menu_bar(app: App, main_window: BrowserWindow) {
id: 'Shuffle',
type: 'checkbox',
accelerator: 'CmdOrCtrl+S',
click: () => {
click() {
web_contents.send('Shuffle')
},
},
Expand All @@ -227,7 +244,7 @@ export function init_menu_bar(app: App, main_window: BrowserWindow) {
id: 'Repeat',
type: 'checkbox',
accelerator: 'CmdOrCtrl+R',
click: () => {
click() {
web_contents.send('Repeat')
},
},
Expand All @@ -236,15 +253,15 @@ export function init_menu_bar(app: App, main_window: BrowserWindow) {
id: 'Volume Up',
label: 'Volume Up',
accelerator: 'CmdOrCtrl+Up',
click: () => {
click() {
web_contents.send('volumeUp')
},
},
{
id: 'Volume Down',
label: 'Volume Down',
accelerator: 'CmdOrCtrl+Down',
click: () => {
click() {
web_contents.send('volumeDown')
},
},
Expand All @@ -257,15 +274,15 @@ export function init_menu_bar(app: App, main_window: BrowserWindow) {
id: 'Back',
label: 'Back',
accelerator: 'CmdOrCtrl+[',
click: () => {
click() {
web_contents.send('Back')
},
},
{
id: 'Forward',
label: 'Forward',
accelerator: 'CmdOrCtrl+]',
click: () => {
click() {
web_contents.send('Forward')
},
},
Expand All @@ -274,15 +291,15 @@ export function init_menu_bar(app: App, main_window: BrowserWindow) {
id: 'Select Next List',
label: 'Select Next List',
accelerator: 'Ctrl+Tab',
click: () => {
click() {
web_contents.send('Select Next List')
},
},
{
id: 'Select Previous List',
label: 'Select Previous List',
accelerator: 'Ctrl+Shift+Tab',
click: () => {
click() {
web_contents.send('Select Previous List')
},
},
Expand Down
1 change: 1 addition & 0 deletions src/electron/typed_ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type Events = {
gonnaQuit: () => void

newPlaylist: (id: string, isFolder: boolean) => void
show_settings: () => void
itunesImport: () => void
import: () => void
filter: () => void
Expand Down

0 comments on commit 5ce4009

Please sign in to comment.