Skip to content

Commit

Permalink
fix: fix #4, and fix bugs relative to layout (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
JellyBrick authored Jun 30, 2023
1 parent e7ee831 commit 486dabc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion MIGRATION_FROM_ALSPOTIFY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 호환되는 것

- `alspotify`와 설정 파일이 호환됩니다. 기존 `alspotify``config.json``alspotron.exe`가 있는 디렉토리에 넣어주시면 됩니다.
- `alspotify`와 설정 파일이 호환됩니다. 기존 `alspotify``config.json``%APPDATA%` (`$XDG_CONFIG_HOME`, `~/Library/Application Support` ) 디렉토리 내 `alspotify` 디렉토리에 넣어주시면 됩니다.

## 호환되지 않는 것

Expand Down
5 changes: 4 additions & 1 deletion renderer/lyrics/SideBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Show, createEffect, createSignal, on } from 'solid-js';

import IconMusic from '../../assets/icon_music.png';
import Card from '../components/Card';
import Marquee from '../components/Marquee';
import useLyricMapper from '../hooks/useLyricMapper';
Expand Down Expand Up @@ -34,7 +35,9 @@ const SideBar = () => {
setArtist(data.artists.join(', '));
setProgress(data.progress);
setDuration(data.duration);
setCoverUrl(data.cover_url);
setCoverUrl(
data.cover_url.match(/^(?:file|https?):\/\//) ? data.cover_url : IconMusic,
);
});

createEffect(on([title, coverUrl, lyricMapper], async () => {
Expand Down
5 changes: 4 additions & 1 deletion renderer/main/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import alsong from 'alsong';
import { For, createEffect, createMemo, createSignal, on } from 'solid-js';
import { TransitionGroup } from 'solid-transition-group';

import IconMusic from '../../assets/icon_music.png';
import useConfig from '../hooks/useConfig';
import useLyricMapper from '../hooks/useLyricMapper';
import { UpdateData } from '../types';
Expand Down Expand Up @@ -48,7 +49,9 @@ const App = () => {
setArtist(data.artists.join(', '));
setProgress(data.progress);
setDuration(data.duration);
setCoverUrl(data.cover_url);
setCoverUrl(
data.cover_url.match(/^(?:file|https?):\/\//) ? data.cover_url : IconMusic,
);
});

createEffect(on([title, coverUrl, lyricMapper], async () => {
Expand Down
14 changes: 10 additions & 4 deletions src/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,11 @@ class Application {
transparent: false,
frame: false,
blur: true,
blurType: 'acrylic',
backgroundColor: '#000000000',
blurType: process.platform === 'win32' ? 'acrylic' : 'blurbehind',
blurGnomeSigma: 100,
blurCornerRadius: 20,
backgroundColor: 'rgba(0, 0, 0, 0.5)',
vibrancy: 'fullscreen-ui',
autoHideMenuBar: true,
resizable: false,
icon: iconPath,
Expand Down Expand Up @@ -246,8 +249,11 @@ class Application {
transparent: false,
frame: false,
blur: true,
blurType: 'acrylic',
backgroundColor: '#000000000',
blurType: process.platform === 'win32' ? 'acrylic' : 'blurbehind',
blurGnomeSigma: 100,
blurCornerRadius: 20,
vibrancy: 'fullscreen-ui',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
autoHideMenuBar: true,
resizable: false,
icon: iconPath,
Expand Down
12 changes: 8 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { app } from 'electron';
import { createSignal } from 'solid-js';

import fs from 'fs/promises';
import path from 'node:path';

export interface Config {
style: {
Expand Down Expand Up @@ -62,10 +64,12 @@ export const DEFAULT_CONFIG = {
syncThrottle: 1000 * 3,
} satisfies Config;

const defaultConfigDirectory = app.getPath('userData');

let configFileTimeout: NodeJS.Timeout | null = null;
const configSignal = createSignal<Config>(DEFAULT_CONFIG);
void (async () => {
const str = await fs.readFile('config.json', 'utf-8').catch(() => JSON.stringify(DEFAULT_CONFIG));
const str = await fs.readFile(path.join(defaultConfigDirectory, 'config.json'), 'utf-8').catch(() => JSON.stringify(DEFAULT_CONFIG));
try {
const config = JSON.parse(str);
configSignal[1](config as Config);
Expand Down Expand Up @@ -111,7 +115,7 @@ export const setConfig = (params: DeepPartial<Config>) => {
configFileTimeout = setTimeout(async () => {
configFileTimeout = null;

await fs.writeFile('config.json', JSON.stringify(configSignal[0](), null, 2), 'utf-8').catch(() => null);
await fs.writeFile(path.join(defaultConfigDirectory, 'config.json'), JSON.stringify(configSignal[0](), null, 2), 'utf-8').catch(() => null);
}, 1000);
};

Expand All @@ -122,7 +126,7 @@ export interface LyricMapper {
let lyricMapperFileTimeout: NodeJS.Timeout | null = null;
const lyricMapperSignal = createSignal<LyricMapper>();
void (async () => {
const str = await fs.readFile('lyrics.json', 'utf-8').catch(() => '{}');
const str = await fs.readFile(path.join(defaultConfigDirectory, 'lyrics.json'), 'utf-8').catch(() => '{}');
try {
const lyricMapper = JSON.parse(str);
lyricMapperSignal[1](lyricMapper as LyricMapper);
Expand All @@ -145,6 +149,6 @@ export const setLyricMapper = (params: Partial<LyricMapper>) => {
lyricMapperFileTimeout = setTimeout(async () => {
lyricMapperFileTimeout = null;

await fs.writeFile('lyrics.json', JSON.stringify(lyricMapperSignal[0](), null, 2), 'utf-8').catch(() => null);
await fs.writeFile(path.join(defaultConfigDirectory, 'lyrics.json'), JSON.stringify(lyricMapperSignal[0](), null, 2), 'utf-8').catch(() => null);
}, 1000);
};

0 comments on commit 486dabc

Please sign in to comment.