Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic support for dark mode & update Swift schema. #1565

Open
wants to merge 4 commits into
base: channel/major-13
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -332,7 +332,7 @@ pipeline {
def releaseUrl = "https://github.com/$GITHUB_OWNER/$GITHUB_REPO/releases/tag/$VERSION"
// Post to Slack
postToSlack('slack-releases-webhook', [[
'title': "Realm Studio $VERSION has been released!",
'title': "Cosmic Realms $VERSION has been released!",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this.

'title_link': releaseUrl,
'text': "Github Release and artifacts are available <${releaseUrl}|here>\n${releaseNotes}",
'mrkdwn_in': ['text'],
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "realm-studio",
"productName": "Realm Studio",
"productName": "Cosmic Realms",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this.

"version": "13.0.2",
"description": "A tool for everything Realm!",
"author": {
@@ -12,7 +12,7 @@
"license": "Apache-2.0",
"main": "./build/main.bundle.js",
"build": {
"appId": "com.mongodb.realm-studio",
"appId": "foundation.wabi.realm-studio",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this.

"directories": {
"buildResources": "./resources"
},
@@ -72,7 +72,7 @@
},
"protocols": [
{
"name": "Realm Studio",
"name": "Cosmic Realms",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this.

"schemes": [
"x-realm-cloud",
"x-realm-studio"
4 changes: 2 additions & 2 deletions scripts/mac/notarize.js
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@ const fs = require("fs");
const path = require("path");
const { notarize } = require("electron-notarize");

const appBundleId = "com.mongodb.realm-studio";
const ascProvider = "QX5CR2FTN2"; // Apple: short team name
const appBundleId = "foundation.wabi.realm-studio";
const ascProvider = "UQ9J5QT9DL"; // Apple: short team name
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this.


exports.notarizeMacApp = async (context) => {
const { APPLE_ID_APP_USERNAME, APPLE_ID_APP_PASSWORD } = process.env;
13 changes: 12 additions & 1 deletion src/main/MainMenu.ts
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ export const getDefaultMenuTemplate = (
store.toggleShowInternalFeatures();
updateMenu();
},
},
},
{ role: 'reload', visible: showInternalFeatures },
{ role: 'toggleDevTools', visible: showInternalFeatures },
{ type: 'separator', visible: showInternalFeatures },
@@ -105,6 +105,17 @@ export const getDefaultMenuTemplate = (
},
},
{ type: 'separator' },
{
label: "Enable Dark Mode",
id: 'toggle-appearance',
type: 'checkbox',
checked: store.shouldShowDarkMode(),
Copy link

@takameyer takameyer Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if this was pulled from the system preferences. Would be great if there was a way to say "use my preferences" and then be able to provide an override.

click: () => {
store.toggleDarkMode();
updateMenu();
},
},
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
2 changes: 1 addition & 1 deletion src/main/Updater.ts
Original file line number Diff line number Diff line change
@@ -216,7 +216,7 @@ export class Updater {
dialog.showMessageBoxSync({
type: 'info',
message: `A new version of ${appName} is downloaded!`,
detail: `${appName} ${lastestVersion} is downloaded.\nClick "Ok" to quit and restart Realm Studio.`,
detail: `${appName} ${lastestVersion} is downloaded.\nClick "Ok" to quit and restart Cosmic Realms.`,
Copy link
Member

@kraenhansen kraenhansen Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this.

buttons: ['Ok'],
defaultId: 0,
}) === 0
4 changes: 2 additions & 2 deletions src/main/WindowManager.ts
Original file line number Diff line number Diff line change
@@ -105,10 +105,10 @@ export class WindowManager {
title: app.name,
width: 800,
height: 600,
vibrancy: 'light',
vibrancy: 'appearance-based',
show: false,
// This should be the same as the value of the SCSS variable $body-bg
backgroundColor: '#f5f5f9',
backgroundColor: '#00000000',
// Accepting the first mouse event, so users dont have to focus windows before clicking them.
// This improves the UX by minimizing the clicks needed to complete a task.
acceptFirstMouse: true,
42 changes: 15 additions & 27 deletions src/services/schema-export/languages/swift.ts
Original file line number Diff line number Diff line change
@@ -38,37 +38,35 @@ export default class SwiftSchemaExporter extends SchemaExporter {
}

public makeSchema(schema: Realm.ObjectSchema) {
this.appendLine(`class ${schema.name}: Object {`);
this.appendLine(`class ${schema.name}: Object\n{\n`);

// Primary key
if (schema.primaryKey) {
this.appendLine(' @Persisted(primaryKey: true)');
this.appendLine(' var ' + schema.primaryKey + ': ObjectId\n');
}

// Properties
const indexedProp: INamedObjectSchemaProperty[] = [];
filteredProperties(schema.properties).forEach(prop => {
this.appendLine(' ' + this.propertyLine(prop));
this.appendLine(' ' + this.propertyLine(prop));
if (prop.indexed && prop.name !== schema.primaryKey) {
indexedProp.push(prop);
}
});

// Primary key
if (schema.primaryKey) {
this.appendLine('');
this.appendLine(' override static func primaryKey() -> String? {');
this.appendLine(' return "' + schema.primaryKey + '"');
this.appendLine(' }');
}

// Indexed Properties
if (indexedProp.length > 0) {
this.appendLine('');
this.appendLine(
' override static func indexedProperties() -> [String] {',
' override static func indexedProperties() -> [String] {',
);

const indexedPropsStr = indexedProp
.map(prop => `"${prop.name}"`)
.join(', ');
this.appendLine(` return [${indexedPropsStr}]`);
this.appendLine(' }');
this.appendLine(` return [${indexedPropsStr}]`);
this.appendLine(' }');
}

// End class
@@ -109,7 +107,7 @@ export default class SwiftSchemaExporter extends SchemaExporter {
if (prop.optional) {
strArray += '?';
}
return `let ${prop.name} = List<${strArray}>()`;
return `@Persisted\n var ${prop.name} = [${strArray}]()\n`;
}

const propType = propertyType(prop.type);
@@ -121,41 +119,31 @@ export default class SwiftSchemaExporter extends SchemaExporter {
case 'int':
case 'float':
case 'double':
return `let ${prop.name} = RealmOptional<${propType}>()`;

case 'string':
case 'data':
case 'date':
case 'objectId':
case 'decimal128':
return `@objc dynamic var ${prop.name}: ${propType}? = nil`;

case 'object':
return `@objc dynamic var ${prop.name}: ${prop.objectType}?`;
return `@Persisted\n var ${prop.name}: ${propType}?\n`;
default:
return `ERROR - unknown type '${prop.type}'`;
}
}

// Non Optional types
const str = `@objc dynamic var ${prop.name}: ${propType} = `;
const str = `@Persisted\n var ${prop.name}: ${propType}\n`;
switch (prop.type) {
case 'bool':
return str + 'false';
case 'int':
case 'float':
case 'double':
return str + '0';
case 'string':
return str + '""';
case 'data':
return str + 'Data()';
case 'date':
return str + 'Date()';
case 'objectId':
return str + 'ObjectId()';
case 'decimal128':
return str + 'Decimal128()';
return str;
case 'object':
return 'Objects must always be optional. Something is not right in this model!';
Copy link
Member

@kraenhansen kraenhansen Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if the changes to the swift schema export went into a separate PR.

}
13 changes: 13 additions & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
@@ -27,17 +27,20 @@ import { WindowType } from './windows/WindowOptions';
type RemovalCallback = () => void;

const KEY_SHOW_SYSTEM_CLASSES = 'browser.show-system-classes';
const KEY_SHOW_DARK_MODE = 'browser.show-dark-mode';
const KEY_SHOW_INTERNAL_FEATURES = 'general.show-internal-features';
const KEY_WINDOW_OPTIONS = 'window-options';

type StudioStore = {
[KEY_SHOW_SYSTEM_CLASSES]: boolean;
[KEY_SHOW_DARK_MODE]: boolean;
[KEY_SHOW_INTERNAL_FEATURES]: boolean;
[key: string]: unknown;
};

class RealmStudioStore {
public readonly KEY_SHOW_SYSTEM_CLASSES = KEY_SHOW_SYSTEM_CLASSES;
public readonly KEY_SHOW_DARK_MODE = KEY_SHOW_DARK_MODE;
public readonly KEY_SHOW_INTERNAL_FEATURES = KEY_SHOW_INTERNAL_FEATURES;
public readonly KEY_WINDOW_OPTIONS = KEY_WINDOW_OPTIONS;

@@ -48,6 +51,12 @@ class RealmStudioStore {
this.store.set(KEY_SHOW_SYSTEM_CLASSES, !currentValue);
}

public toggleDarkMode()
{
const currentValue = this.shouldShowInternalFeatures();
Copy link
Member

@kraenhansen kraenhansen Mar 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line seems incorrect.

this.store.set(KEY_SHOW_DARK_MODE, !currentValue);
}

public toggleShowInternalFeatures() {
const currentValue = this.shouldShowInternalFeatures();
this.store.set(KEY_SHOW_INTERNAL_FEATURES, !currentValue);
@@ -57,6 +66,10 @@ class RealmStudioStore {
return this.store.get(KEY_SHOW_SYSTEM_CLASSES, false);
}

public shouldShowDarkMode(): boolean {
return this.store.get(KEY_SHOW_DARK_MODE, false);
}

public shouldShowInternalFeatures(): boolean {
return this.store.get(KEY_SHOW_INTERNAL_FEATURES, false);
}
4 changes: 2 additions & 2 deletions src/testing/post-packaging/index.ts
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ assert(

assert.strictEqual(typeof productName, 'string', 'Expected a product name');

describe('Realm Studio packaged', () => {
describe('Cosmic Realms packaged', () => {
let mockedS3: http.Server;
let appProcess: cp.ChildProcess;
let temporaryMacPath: string;
@@ -130,7 +130,7 @@ describe('Realm Studio packaged', () => {
buildMockedRealmStudio();
// Copy the current dist/mac folder to a different location to prevent the auto updater
// from overriding the current dist/mac folder.
const originalMacPath = path.resolve(distPath, 'mac');
const originalMacPath = path.resolve(distPath, 'mac-arm64');
temporaryMacPath = fs.mkdtempSync(originalMacPath + '-auto-update-test-');
console.log(
'Making a copy of the mac app from',
2 changes: 1 addition & 1 deletion src/testing/post-packaging/mocked-realm-studio/index.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ electron.app.once('ready', () => {
message: `Writing to the ready signal: ${p}`,
});
*/
fs.writeFileSync(p, 'Hello from a future Realm Studio!', {
fs.writeFileSync(p, 'Hello from a future Cosmic Realms!', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this.

encoding: 'utf8',
});
// Exit ...
35 changes: 30 additions & 5 deletions src/testing/post-packaging/mocked-realm-studio/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/testing/post-packaging/mocked-realm-studio/package.json
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@
},
"license": "Apache-2.0",
"build": {
"appId": "com.mongodb.realm-studio",
"productName": "Realm Studio",
"appId": "foundation.wabi.realm-studio",
"productName": "Cosmic Realms",
Comment on lines +13 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this.

"mac": {
"target": [
"zip"
22 changes: 16 additions & 6 deletions src/ui/Greeting/Greeting.scss
Original file line number Diff line number Diff line change
@@ -31,8 +31,12 @@ $history-panel-icon-size: 20px;
}

&__ActionsPanel {
@include themed() {
border: 1px solid mix(t("elephant"), t("dove"), 25%);
background-color: t("base");
background: t("base");
}
align-items: center;
background: $window-background;
display: flex;
flex-basis: 60%;
flex-direction: column;
@@ -112,13 +116,17 @@ $history-panel-icon-size: 20px;
}

&__HistoryPanel {
background: $charcoal;
color: $dove;
@include themed() {
background: t("charcoal");
color: t("dove");
}
flex-grow: 1;
font-size: .9rem;

a {
color: $dove;
@include themed() {
color: t("dove");
}
}

&__Entry {
@@ -162,9 +170,11 @@ $history-panel-icon-size: 20px;
}

&__CloudOverlay {
background: $overlay-background;
@include themed() {
color: t("dove");
background: rgba(t("charcoal"), .6);
}
bottom: 0;
color: $dove;
display: flex;
flex-direction: column;
left: 0;
Loading