Skip to content

Commit

Permalink
app: Ensure API key
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser committed Jan 14, 2021
1 parent 30bd3b5 commit f7ea188
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
34 changes: 18 additions & 16 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ app.allowRendererProcessReuse = true;
// Setup application menu
setupMenu(mainStore);

// Setup theme from configuration
reaction(
() => mainStore.config.theme,
schema => {
nativeTheme.themeSource = schema;

const bg = nativeTheme.shouldUseDarkColors
? theme.dark.background
: theme.light.background;
win?.setBackgroundColor(bg);
},
{fireImmediately: true}
);

// Require overlay main functionality
require('src/overlay/overlays/nowPlaying/main');

let win: BrowserWindow | null;

const createWindow = () => {
Expand Down Expand Up @@ -83,6 +100,7 @@ const createWindow = () => {

app.on('ready', async () => {
await loadMainConfig(mainStore);
mainStore.config.ensureDefaults();
createWindow();

registerMainIpc(mainStore);
Expand Down Expand Up @@ -136,9 +154,6 @@ app.on('ready', async () => {
{fireImmediately: true}
);

// Require overlay main functionality
require('src/overlay/overlays/nowPlaying/main');

connectNetworkStore(mainStore, network);
registerDebuggingEventsService(mainStore, network);
});
Expand All @@ -152,16 +167,3 @@ app.on('activate', () => {
createWindow();
}
});

reaction(
() => mainStore.config.theme,
schema => {
const bg = nativeTheme.shouldUseDarkColors
? theme.dark.background
: theme.light.background;

nativeTheme.themeSource = schema;
win?.setBackgroundColor(bg);
},
{fireImmediately: true}
);
13 changes: 10 additions & 3 deletions src/shared/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,13 @@ export class AppConfig {
@observable
enableCloudApi = false;
/**
* Unique identifier used to identify the application to the server.
* Unique identifier used to identify the application to the server. Changing
* this will change all derrived identifiers.
*
* Will be generated on the users first run of the application.
*/
@serializable
@observable
apiKey = uuid();
apiKey = '';
/**
* Mark tracks as 'IDs' using this string
*/
Expand Down Expand Up @@ -208,6 +210,11 @@ export class AppConfig {
this.theme = this.theme === 'light' ? 'dark' : 'light';
}

@action
ensureDefaults() {
this.apiKey = this.apiKey === '' ? uuid() : this.apiKey;
}

constructor() {
makeAutoObservable(this);
}
Expand Down

0 comments on commit f7ea188

Please sign in to comment.