Skip to content

Commit

Permalink
Merge branch 'feature/JS-6113-space-store-migration' into nightly-ci-…
Browse files Browse the repository at this point in the history
…test
  • Loading branch information
fb929 committed Jan 27, 2025
2 parents ca8ace9 + c52b203 commit aec0a5a
Show file tree
Hide file tree
Showing 163 changed files with 2,290 additions and 1,561 deletions.
6 changes: 5 additions & 1 deletion dist/challenge/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
body { font-family: 'Inter', Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; background-color: #fff; color: #252525; }

.content { display: flex; align-items: center; justify-content: center; flex-direction: column; padding: 16px; height: 100%; }
.title { font-size: 18px; line-height: 26px; letter-spacing: -0.28px; font-weight: 700; margin: 0px 0px 24px 0px; text-align: center; }
.title { font-size: 18px; line-height: 26px; letter-spacing: -0.28px; font-weight: 700; margin: 0px 0px 4px 0px; text-align: center; }
.description { font-size: 14px; line-height: 22px; letter-spacing: -0.28px; font-weight: 400; margin: 0px 0px 24px 0px; text-align: center; }

#challenge { display: flex; align-items: center; justify-content: center; flex-direction: row; gap: 0px 8px; }
#challenge .number { background-color: #f2f2f2; border-radius: 12px; font-weight: 700; font-size: 36px; line-height: 40px; padding: 12px; }
Expand All @@ -31,13 +32,15 @@
<body>
<div class="content">
<div id="title" class="title"></div>
<div id="description" class="description"></div>
<div id="challenge"></div>
</div>
<script type="text/javascript">
$(() => {
const win = $(window);
const html = $('html')
const title = $('#title');
const description = $('#description');
const challengeEl = $('#challenge');

window.Electron.on('challenge', (e, data) => {
Expand All @@ -57,6 +60,7 @@
contentType: 'application/json',
success: data => {
title.text(data.challengeTitle);
description.text(data.challengeDescription);
},
});
});
Expand Down
25 changes: 24 additions & 1 deletion dist/embed/iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
// Github Gist
if (processor == Processor.GithubGist) {
loadGithubGist(html);
} else
if (processor == Processor.Kroki) {
loadKroki(html);
} else {
if ((processor == Processor.Telegram) && !html.match(/<script/)) {
const post = html.replace(/^https:\/\/t.me\//, '');
Expand Down Expand Up @@ -179,7 +182,7 @@

function resize () {
const height = useRootHeight ? root.height() : document.documentElement.scrollHeight;
window.parent.postMessage({ height, blockId }, '*');
window.parent.postMessage({ type: 'resize', height, blockId }, '*');
};

function insertHtml (html) {
Expand Down Expand Up @@ -246,6 +249,26 @@
});
};

function loadKroki (html) {
if (!html) {
return;
};

$.ajax({
url: html,
dataType: 'text',
timeout: 1000,
success: (data) => {
root.html(data);

root.find('a').off('click').on('click', function (e) {
e.preventDefault();
window.parent.postMessage({ type: 'openUrl', url: $(this).attr('href') }, '*');
});
}
});
};

function getEnvironmentContent (processor) {
const libs = [];

Expand Down
14 changes: 13 additions & 1 deletion electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ const remote = require('@electron/remote/main');
const { installNativeMessagingHost } = require('./electron/js/lib/installNativeMessagingHost.js');
const binPath = fixPathForAsarUnpack(path.join(__dirname, 'dist', `anytypeHelper${is.windows ? '.exe' : ''}`));
const Store = require('electron-store');
const suffix = app.isPackaged ? '' : 'dev';
const store = new Store({ name: [ 'localStorage', suffix ].join('-') });

// Fix notifications app name
if (is.windows) {
app.setAppUserModelId(app.name);
};

storage.setDataPath(app.getPath('userData'));
Store.initRenderer();
//Store.initRenderer();

const Api = require('./electron/js/api.js');
const ConfigManager = require('./electron/js/config.js');
Expand Down Expand Up @@ -53,6 +55,16 @@ powerMonitor.on('resume', () => {
Util.log('info', '[PowerMonitor] resume');
});

ipcMain.on('storeGet', (e, key) => {
e.returnValue = store.get(key);
});
ipcMain.on('storeSet', (e, key, value) => {
e.returnValue = store.set(key, value);
});
ipcMain.on('storeDelete', (e, key) => {
e.returnValue = store.delete(key);
});

let deeplinkingUrl = '';
let waitLibraryPromise = null;
let mainWindow = null;
Expand Down
4 changes: 4 additions & 0 deletions electron/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ class Api {
WindowManager.createChallenge(param);
};

hideChallenge (win, param) {
WindowManager.closeChallenge(param);
};

reload (win, route) {
win.route = route;
win.webContents.reload();
Expand Down
9 changes: 3 additions & 6 deletions electron/js/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ const os = require('os');
const path = require('path');
const mime = require('mime-types');
const tmpPath = () => app.getPath('temp');
const Store = require('electron-store');
const suffix = app.isPackaged ? '' : 'dev';
const store = new Store({ name: [ 'localStorage', suffix ].join('-') });

contextBridge.exposeInMainWorld('Electron', {
version: {
Expand All @@ -19,9 +16,9 @@ contextBridge.exposeInMainWorld('Electron', {
platform: os.platform(),
arch: process.arch,

storeSet: (key, value) => store.set(key, value),
storeGet: key => store.get(key),
storeDelete: key => store.delete(key),
storeGet: key => ipcRenderer.sendSync('storeGet', key),
storeSet: (key, value) => ipcRenderer.sendSync('storeSet', key, value),
storeDelete: key => ipcRenderer.sendSync('storeDelete', key),

isPackaged: app.isPackaged,
userPath: () => app.getPath('userData'),
Expand Down
32 changes: 18 additions & 14 deletions electron/js/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class WindowManager {
list = new Set();

create (options, param) {
const { route, isChild } = options;
const { hideMenuBar } = ConfigManager.config;

param = Object.assign({
Expand All @@ -45,8 +44,7 @@ class WindowManager {

remote.enable(win.webContents);

win.isChild = isChild;
win.route = route;
win = Object.assign(win, options);
win.windowId = win.id;

this.list.add(win);
Expand Down Expand Up @@ -144,33 +142,39 @@ class WindowManager {
createChallenge (options) {
const { screen } = require('electron');
const primaryDisplay = screen.getPrimaryDisplay();
const { width } = primaryDisplay.workAreaSize;
const { width, height } = primaryDisplay.workAreaSize;

const win = this.create({}, {
const win = this.create({ ...options, isChallenge: true }, {
backgroundColor: '',
width: 424,
height: 232,
x: Math.floor(width / 2 - 212),
y: 50,
y: Math.floor(height - 282),
titleBarStyle: 'hidden',
alwaysOnTop: true,
focusable: true,
skipTaskbar: true,
});

win.loadURL('file://' + path.join(Util.appPath, 'dist', 'challenge', `index.html`));
win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
win.loadURL('file://' + path.join(Util.appPath, 'dist', 'challenge', 'index.html'));
win.setMenu(null);

is.windows || is.linux ? win.showInactive() : win.show();
win.focus();
win.showInactive(); // show inactive to prevent focus loose from other app

win.webContents.once('did-finish-load', () => {
win.webContents.postMessage('challenge', options);
});

setTimeout(() => {
if (win && !win.isDestroyed()) {
setTimeout(() => this.closeChallenge(options), 30000);
return win;
};

closeChallenge (options) {
for (const win of this.list) {
if (win && win.isChallenge && (win.challenge == options.challenge) && !win.isDestroyed()) {
win.close();
};
}, 30000);
return win;
};
};

command (win, cmd, param) {
Expand Down
19 changes: 15 additions & 4 deletions electron/json/cors.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"https://cdnjs.cloudflare.com",
"https://*.bilibili.com",
"https://s1.hdslb.com",
"https://static.sketchfab.com"
"https://static.sketchfab.com",
"https://*.bstarstatic.com"
],

"font-src": [
Expand All @@ -69,7 +70,8 @@
"https://*.fbcdn.net",
"https://static.cdninstagram.com",
"https://telegram.org",
"https://static.sketchfab.com"
"https://static.sketchfab.com",
"https://*.bstarstatic.com"
],

"connect-src": [
Expand Down Expand Up @@ -121,7 +123,11 @@
"https://media.sketchfab.com",
"https://sentry.io",
"https://*.any.coop",
"https://*.amplitude.com"
"https://*.amplitude.com",
"https://kroki.io",
"https://*.vimeo.com",
"https://*.statsigapi.net",
"https://*.bstarstatic.com"
],

"script-src-elem": [
Expand Down Expand Up @@ -155,7 +161,11 @@
"https://codepen.io",
"https://cdnjs.cloudflare.com",
"https://*.hdslb.com",
"https://static.sketchfab.com"
"https://static.sketchfab.com",
"https://*.codepenassets.com",
"https://*.bstarstatic.com",
"https://*.googletagmanager.com",
"https://*.facebook.net"
],

"frame-src": [
Expand All @@ -171,6 +181,7 @@
"https://*.figma.com",
"https://*.github.com",
"https://*.bilibili.com",
"https://*.bilibili.tv",
"https://platform.twitter.com",
"https://*.openstreetmap.org",
"https://embed.reddit.com",
Expand Down
2 changes: 2 additions & 0 deletions extension/popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const Index = observer(class Index extends React.Component<I.PageComponent, Stat
login () {
const appKey = Storage.get('appKey');

console.log('appKey', appKey);

if (appKey) {
Util.authorize(appKey, () => {
const { serverPort, gatewayPort } = S.Extension;
Expand Down
2 changes: 1 addition & 1 deletion middleware.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.38.7
0.39.0-rc08
16 changes: 8 additions & 8 deletions package-lock.json

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

Loading

0 comments on commit aec0a5a

Please sign in to comment.